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 SharedConstants.java:
				
/*                                               
 * Class Name:   SharedConstants
 *
 * Purpose:  Shared Constants, including development time trace constants
 *
 * Owner:
 * Version: 1.0
 */ 
public class SharedConstants
{
  public static final String COPYRIGHT = "(c) Copyright ...";
  /* Create static variables to implement trace. */
  /* Variables must be declared as final! */
  /* Declaring a variable as final indicates (and enforces) that the   */
  /* value of the variable will not change from its initial value.     */
  /* During development, set the DEBUG variable to the desired output  */
  /* trace level.                                                      */
  /* When making changes to any of the variables, you must recompile   */
  /* all Java source code that makes use of these variables, or code   */
  /* that makes use of variables that in turn make use of these        */
  /* variables, and so on. This step is necessary because the Java     */
  /* compiler optimizes your code by directly inserting the variables  */
  /* values into code that makes use of them. Hence, the compiler will */
  /* not automatically detect the need to compile all affected files   */ 
  /* through its prerequisite checking.                                */
  public static final int TRACE_OFF    = 0x0000;
  public static final int TRACE_LOW    = 0x0001;
  public static final int TRACE_MEDIUM = 0x0002 | TRACE_LOW;
  public static final int TRACE_HIGH   = 0x0004 | TRACE_LOW | TRACE_MEDIUM;
  public static final int TRACE_ALL    = TRACE_LOW |TRACE_MEDIUM | TRACE_HIGH;
  /* When building final build for application deployment, set to off, 
  /* during development, set to desired trace level */
  //public static final int DEBUG = TRACE_OFF;
  //public static final int DEBUG = TRACE_LOW;
  public static final int DEBUG = TRACE_MEDIUM;
  //public static final int DEBUG = TRACE_HIGH;
  //public static final int DEBUG = TRACE_ALL;
}
      

Return to the article.

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