bcds.tools
Class DL

java.lang.Object
  extended by bcds.tools.DL

public class DL
extends java.lang.Object

Provides a very simplistic logger for "debug". Logging can be controlled through two environment variables:

The net effect is that the same program that includes calls to the various DL.log functions will generate or not the debugging messages based on the presence and values of these environment variables.

Code examples:

  1. DL.log("a message");
    Will be logged always if logging is enabled.
  2. DL.log(10, "abc");
    Will be logged if level >= 10.
  3. DL.log("Error %s: %d", s, v);
    Same as the first above but with a format specifier.
  4. DL.log(20, "Error %s: %d", s, v);
    A combination of 2) and 3)

How to use:

    $ DL_Level=0 java myprogram

    - Output goes to stderr. Everything is logged.

    $ DL_Level=0 DL_File=/tmp/err.log java myprogram

    - Output goes to /tmp/err.log, which is overwritten every
      time the program is executed. Everything is logged.

    $ DL_Level=0 DL_File=+/tmp/err.log java myprogram

    - Same as before, but now the log messages are appended
      to the file.
 

Note: The desired level of logging and the destination file cannot be changed after program initialization (they remain constant throughout the program execution). Also, all methods and variables are static, so that effectively only one instance per application will ever exist. In fact, instantiation is disabled.

Author:
Juan Segovia S.

Method Summary
static byte getLevel()
          Returns the current minimum logging level.
static boolean isEnabled()
          Returns true if the current logging level is less than Integer.MAX_VALUE.
static void log(byte n, java.lang.String msg)
          Logs a message n is at least equal to the current logging level.
static void log(byte n, java.lang.String fmt, java.lang.Object... args)
          Logs a formatted message n is at least equal to the current logging level.
static void log(java.lang.String msg)
          Logs a message if isEnabled() is true; otherwise the message is discarded.
static void log(java.lang.String fmt, java.lang.Object... args)
          Logs a formatted string using Locale.US as the locale.
static void main(java.lang.String[] args)
           
static void setLevel(byte n)
          Sets the minimum logging level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setLevel

public static void setLevel(byte n)
Sets the minimum logging level. Log messages with a level lower than n are discarded.


getLevel

public static byte getLevel()
Returns the current minimum logging level.


isEnabled

public static boolean isEnabled()
Returns true if the current logging level is less than Integer.MAX_VALUE.


log

public static void log(java.lang.String msg)
Logs a message if isEnabled() is true; otherwise the message is discarded.


log

public static void log(java.lang.String fmt,
                       java.lang.Object... args)
Logs a formatted string using Locale.US as the locale.


log

public static void log(byte n,
                       java.lang.String msg)
Logs a message n is at least equal to the current logging level.


log

public static void log(byte n,
                       java.lang.String fmt,
                       java.lang.Object... args)
Logs a formatted message n is at least equal to the current logging level.


main

public static void main(java.lang.String[] args)