IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  Java technology  >

Techniques for adding trace statements to your Java application

Use tracing during development as well as after your application is deployed

developerWorks


File MainApplication.java:
				
/*                                               
 * Class Name:   MainApplication
 *
 * Purpose:  Sample application to demonstrate tracing
 *
 * Owner:
 * Version: 1.0
 */                
  
public class MainApplication
{
   public static void main(String[] args)
   {
      /* Before executing a trace output call, issue a check to see if */
      /* run-time tracing has been turned on                           */
      /* Run-time trace example */
      if ( PrintMessage.isRuntimeDebugOn() )
      {
         PrintMessage.printMessageWithDateTime("main():  Run-time message 1");
      }
  
      /* Combining run-time trace output calls with exceptions can be */
      /* an effective trace strategy.                                 */
      /* Run-time trace example */
      try { throw new Exception("error"); }
      catch (Throwable t)
      {
         if ( PrintMessage.isRuntimeDebugOn() )
         {
           PrintMessage.printMessage("main():  Run-time message 2");
           t.printStackTrace();
         }
      }
   } /*end main() */
} /* end class definition */
      

Return to the article.

    关于 IBM 隐私条约 联系 IBM 使用条款