Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.flexstor.common.util
Class Diagnostic  view Diagnostic download Diagnostic.java

java.lang.Object
  extended bycom.flexstor.common.util.DiagnosticCategoryI
      extended bycom.flexstor.common.util.DiagnosticBase
          extended bycom.flexstor.common.util.Diagnostic

public class Diagnostic
extends DiagnosticBase

Revision 1.8 2000-09-28 : 22:51:00 Visesh Removed constructors particular to DiagnosticCategory when it was in the hiearchy Diagnostic is a utility class for tracing and debugging. It is not intended for error and exception handling. It provides methods to print, trace, and warn and also to check for conditions. One or more output streams can be registered so that output can be saved in a file and shown on the console simultaneously.

Diagnostic.initialize(section name) must be called to read properties from the 'diagnostic.properties' file. Different section can be defined with different properties, e.g. for different applications.

These are the available properties

Time Format Syntax:
To specify the time format use a time pattern string. In this pattern, all ASCII letters are reserved as pattern letters, which are defined as the following:

 
 Symbol   Meaning                 Presentation        Example
  ------   -------                 ------------        -------
  G        era designator          (Text)              AD
  y        year                    (Number)            1996
  M        month in year           (Text & Number)     July & 07
  d        day in month            (Number)            10
  h        hour in am/pm (1~12)    (Number)            12
  H        hour in day (0~23)      (Number)            0
  m        minute in hour          (Number)            30
  s        second in minute        (Number)            55
  S        millisecond             (Number)            978
  E        day in week             (Text)              Tuesday
  D        day in year             (Number)            189
  F        day of week in month    (Number)            2 (2nd Wed in July)
  w        week in year            (Number)            27
  W        week in month           (Number)            2
  a        am/pm marker            (Text)              PM
  k        hour in day (1~24)      (Number)            24
  K        hour in am/pm (0~11)    (Number)            0
  z        time zone               (Text)              Pacific Standard Time
  '        escape for text         (Delimiter)
  ''       single quote            (Literal)           '
 
The count of pattern letters determine the format. (Text): 4 or more pattern letters--use full form, < 4--use short or abbreviated form if one exists. (Number): the minimum number of digits. Shorter numbers are zero-padded to this amount. Year is handled specially; that is, if the count of 'y' is 2, the Year will be truncated to 2 digits. (Text & Number): 3 or over, use text, otherwise use number. Any characters in the pattern that are not in the ranges of ['a'..'z'] and ['A'..'Z'] will be treated as quoted text. For instance, characters like ':', '.', ' ', '#' and '@' will appear in the resulting time text even they are not embraced within single quotes. A pattern containing any invalid pattern letter will result in a thrown exception during formatting or parsing. Examples Using the US Locale:
 
 Format Pattern                         Result
  --------------                         -------
  "yyyy.MM.dd G 'at' hh:mm:ss z"    ->>  1996.07.10 AD at 15:08:56 PDT
  "EEE, MMM d, ''yy"                ->>  Wed, July 10, '96
  "h:mm a"                          ->>  12:08 PM
  "hh 'o''clock' a, zzzz"           ->>  12 o'clock PM, Pacific Daylight Time
  "K:mm a, z"                       ->>  0:00 PM, PST
  "yyyyy.MMMMM.dd GGG hh:mm aaa"    ->>  1996.July.10 AD 12:08 PM
 

Categories must be defined in DiagnosticCategoryI.

Categories must start with the prefix 'category.name.', the trace level for each category has a prefix of 'category.traceLevel.' with the category name following.

A sample diagnostic section in 'diagnostic.properties'. This file is to be expected in the conf directory.

 
    [client]
    output=true
    printTimeStamp=true
    printThreadId=true
    timeFormat=dd-kk:mm:ss:SSS
    outputToConsole=true
    redirectOutput=true
    traceDir=d:\fsdb\debug\
    traceFile=diagnostic.txt
    checking=true
    traceLevel=10
    category.name.Send=Send
    category.traceLevel.Send=5
 

    Test Run Output: (*** indicates the code executing)
    
 21-12:36:49:482 | main | Current test settings:
 21-12:36:49:492 | main | Number of output devices:2
 21-12:36:49:502 | main | Default time stamp=1999-04-21 12:36:49:492
 21-12:36:49:502 | main | Current time stamp=21-12:36:49:502
 21-12:36:49:502 | main | TraceLevel=10
 21-12:36:49:512 | main | Checking=true
 21-12:36:49:522 | main | ThreadId=main
 21-12:36:49:522 | main | Categories:
 21-12:36:49:532 | main | Process
 21-12:36:49:532 | main | Send
 21-12:36:49:532 | main | 
 21-12:36:49:532 | main | Test begin
 21-12:36:49:662 | 1 | *** Diagnostic.trace(1, "Trace for level 1")
 21-12:36:49:662 | 1 | [1]  Trace for level 1
 21-12:36:49:662 | 1 | *** Diagnostic.trace(3, "Trace for level 3")
 21-12:36:49:672 | 1 | [3]      Trace for level 3
 21-12:36:49:672 | 1 | *** Diagnostic.trace(5, "Trace for level 5")
 21-12:36:49:682 | 1 | [5]          Trace for level 5
 21-12:36:49:682 | 1 | *** Diagnostic.trace(Diagnostic.CAT_ARCHIVE, "Trace for category Archive")
 21-12:36:49:682 | 1 | *** Diagnostic.trace(Diagnostic.CAT_SEND, "Trace for category Send")
 21-12:36:49:692 | 1 | [Send] Trace for category Send
 21-12:36:49:692 | 1 | *** Diagnostic.precondition((5 < 9), "Precondition 5 < 9")
 21-12:36:49:702 | 1 | *** Diagnostic.precondition((5 > 9), "Precondition 5 > 9")
 21-12:36:49:702 | 1 | Precondition failed: Precondition 5 > 9
 21-12:36:49:792 | 1 | com.flexstor.common.util.DiagnosticPreconditionException: Precondition 5 > 9
 21-12:36:49:792 | 1 | 	at com.flexstor.common.util.Diagnostic.precondition(Diagnostic.java:359)
 21-12:36:49:792 | 1 | 	at com.flexstor.common.util.Diagnostic$TestThread.run(Diagnostic.java:1019)
 21-12:36:49:852 | 1 | *** Diagnostic.warn(2, true, "Warning level 2, condition true")
 21-12:36:49:852 | 1 | wn[2]     Warning level 2, condition true
 21-12:36:49:852 | 1 | *** Diagnostic.warn(2, false, "Warning level 2, condition false")
 21-12:36:49:852 | 1 | *** Diagnostic.warn(5, true, "Warning level 5, condition true")
 21-12:36:49:862 | 1 | wn[5]           Warning level 5, condition true
 21-12:36:49:862 | 1 | *** Diagnostic.warn(Diagnostic.CAT_SEND, "Warning category 'Send'")
 21-12:36:49:862 | 1 | wn[Send] Warning category 'Send'
 21-12:36:49:872 | 1 | *** Diagnostic.warn(Diagnostic.CAT_ARCHIVE, "Warning for category 'Archive'")
 21-12:36:49:872 | 1 | *** Diagnostic.needException()
 21-12:36:49:872 | 1 | Check failed: Need Exception
 21-12:36:49:882 | 1 | *** Diagnostic.fail(new Exception("Failing"))
 21-12:36:49:882 | 1 | Failing
 21-12:36:49:892 | 1 | java.lang.Exception: Failing
 21-12:36:49:892 | 1 | 	at com.flexstor.common.util.Diagnostic$TestThread.run(Diagnostic.java:1034)
 21-12:36:49:892 | 1 | *** Diagnostic.printStackTrace()
 21-12:36:49:932 | 1 | java.lang.Exception: Diagnostic Stack Trace
 21-12:36:49:932 | 1 | 	at com.flexstor.common.util.Diagnostic.printStackTrace(Diagnostic.java:539)
 21-12:36:49:932 | 1 | 	at com.flexstor.common.util.Diagnostic$TestThread.run(Diagnostic.java:1037)
 21-12:36:49:942 | 1 | *** Diagnostic.printStackTrace(Diagnostic.CAT_SEND, 5, new Exception())
 21-12:36:49:952 | 1 | java.lang.Exception
 21-12:36:49:952 | 1 | 	at com.flexstor.common.util.Diagnostic$TestThread.run(Diagnostic.java:1039)
 21-12:36:49:952 | 1 | *** Test completed
 


Field Summary
private static java.lang.String DIAGNOSTIC_CATEGORY_FILE
           
private static java.lang.String DIAGNOSTIC_CATEGORY_LEVEL
           
private static java.lang.String DIAGNOSTIC_CATEGORY_PREFIX
           
private static java.lang.String DIAGNOSTIC_CHECKING_ENABLED
           
private static java.lang.String DIAGNOSTIC_OUTPUT_CONSOLE
           
private static java.lang.String DIAGNOSTIC_OUTPUT_ENABLED
           
private static java.lang.String DIAGNOSTIC_PRINT_THREADID
           
private static java.lang.String DIAGNOSTIC_PRINT_TIME
           
private static java.lang.String DIAGNOSTIC_PROPERTIES_FILE
           
private static java.lang.String DIAGNOSTIC_REDIR_OUTPUT
           
private static java.lang.String DIAGNOSTIC_TIME_FORMAT
           
private static java.lang.String DIAGNOSTIC_TRACE_DIR
           
private static java.lang.String DIAGNOSTIC_TRACE_FILE
           
private static java.lang.String DIAGNOSTIC_TRACE_LEVEL
           
private static Diagnostic instance
           
 
Fields inherited from class com.flexstor.common.util.DiagnosticBase
bChecking, bOutput, bOutputConsole, bPrintThreadId, bPrintTime, bPropertiesLoaded, categoryTraceLevels, COL_SEPARARTOR, DEFAULT_TIME_FORMAT, fileTraceCategories, indent, outLevel, outputDevices, outputDevicesCategory, systemOut, timeFormat, traceCategories
 
Fields inherited from class com.flexstor.common.util.DiagnosticCategoryI
APPSERVER_ARCHIVE, APPSERVER_IMPORT, APPSERVER_MAIN, APPSERVER_QMANAGER, APPSERVER_SERVICES, ASSET_REG, ASSET_VERSIONS, CAT_ARCHIVE, CAT_CLASSGEN, CAT_CLASSLDR, CAT_EXPORT, CAT_GATEWAY, CAT_IMPORT, CAT_OAS, CAT_PROCESS, CAT_REPORT, CAT_SCRIPT_SVC, CAT_SEND, CAT_THREAD_MGR, categories, REGISTRY, SETTINGS
 
Constructor Summary
Diagnostic()
           
 
Method Summary
private static void getProperties(java.lang.String sDiagnosticSection)
          Gets the properties from the properties file.
static void initialize(java.lang.String sSectionName)
          Initializes Diagnostic by reading a section from the diagnostic.properties file and adding an instance to ObjectHolder to prevent garbage collection.
static void main(java.lang.String[] args)
          For demonstration purposes.
 
Methods inherited from class com.flexstor.common.util.DiagnosticBase
addOutputDevice, addOutputDevice, addOutputDevice, addOutputDevice, addTraceCategory, check, enableChecking, enableOutput, enableTimeStamp, fail, getThreadId, getTraceLevel, getTraceLevel, isOutputEnabled, isOutputLevel, isRegisteredCategory, needException, precondition, println, println, printMemStatus, printOneLine, printOneStackTrace, printStackTrace, printStackTrace, printStackTrace, printStackTrace, printStackTrace, removeTraceCategory, setTraceLevel, trace, trace, trace, warn, warn, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIAGNOSTIC_PROPERTIES_FILE

private static final java.lang.String DIAGNOSTIC_PROPERTIES_FILE
See Also:
Constant Field Values

DIAGNOSTIC_TRACE_DIR

private static final java.lang.String DIAGNOSTIC_TRACE_DIR
See Also:
Constant Field Values

DIAGNOSTIC_TRACE_FILE

private static final java.lang.String DIAGNOSTIC_TRACE_FILE
See Also:
Constant Field Values

DIAGNOSTIC_TRACE_LEVEL

private static final java.lang.String DIAGNOSTIC_TRACE_LEVEL
See Also:
Constant Field Values

DIAGNOSTIC_REDIR_OUTPUT

private static final java.lang.String DIAGNOSTIC_REDIR_OUTPUT
See Also:
Constant Field Values

DIAGNOSTIC_OUTPUT_ENABLED

private static final java.lang.String DIAGNOSTIC_OUTPUT_ENABLED
See Also:
Constant Field Values

DIAGNOSTIC_PRINT_TIME

private static final java.lang.String DIAGNOSTIC_PRINT_TIME
See Also:
Constant Field Values

DIAGNOSTIC_TIME_FORMAT

private static final java.lang.String DIAGNOSTIC_TIME_FORMAT
See Also:
Constant Field Values

DIAGNOSTIC_PRINT_THREADID

private static final java.lang.String DIAGNOSTIC_PRINT_THREADID
See Also:
Constant Field Values

DIAGNOSTIC_OUTPUT_CONSOLE

private static final java.lang.String DIAGNOSTIC_OUTPUT_CONSOLE
See Also:
Constant Field Values

DIAGNOSTIC_CHECKING_ENABLED

private static final java.lang.String DIAGNOSTIC_CHECKING_ENABLED
See Also:
Constant Field Values

DIAGNOSTIC_CATEGORY_PREFIX

private static final java.lang.String DIAGNOSTIC_CATEGORY_PREFIX
See Also:
Constant Field Values

DIAGNOSTIC_CATEGORY_LEVEL

private static final java.lang.String DIAGNOSTIC_CATEGORY_LEVEL
See Also:
Constant Field Values

DIAGNOSTIC_CATEGORY_FILE

private static final java.lang.String DIAGNOSTIC_CATEGORY_FILE
See Also:
Constant Field Values

instance

private static Diagnostic instance
Constructor Detail

Diagnostic

public Diagnostic()
Method Detail

initialize

public static void initialize(java.lang.String sSectionName)
Initializes Diagnostic by reading a section from the diagnostic.properties file and adding an instance to ObjectHolder to prevent garbage collection.


getProperties

private static void getProperties(java.lang.String sDiagnosticSection)
Gets the properties from the properties file. Uses an PropertyMapper to read the file.


main

public static void main(java.lang.String[] args)
For demonstration purposes. Run this class to see how to use it.