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)
   {
      /* Each of the following examples show how to code calls to the        */
      /* development-time trace mechanism.  Each call first checks the value */
      /* of the trace variable, by direct call to the public variables       */
      /* themselves.                                                         */
      /* Development time trace example */
      if ( PrintMessage.traceLow )
      {
        PrintMessage.printMessageWithDateTime("main():Develop-time message1"); 
      }
      /* Development time trace example */
      if ( PrintMessage.traceMedium )
      {
        PrintMessage.printMessageWithDateTime("main():Develop-time message2"); 
      }
      /* Development time trace example */
      if ( PrintMessage.traceHigh )
      {
        PrintMessage.printMessageWithDateTime("main():Develop-time message3"); 
      }
      /* Development time trace example */
      try { throw new Exception("error"); }
      catch (Throwable t)
      {
         if ( PrintMessage.traceAll )
         {
           PrintMessage.printMessage("main():  Development-time message 4");
           t.printStackTrace();
         }
      }
   } /*end main() */
} /* end class definition */
      

Return to the article.

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