HOME

com.ireasoning.util
Class Logger

java.lang.Object
  extended bycom.ireasoning.util.Logger

public final class Logger
extends Object

Logger implementation. It has six logging levels (from low to high) : DEBUG, INFO, WARN, ERROR, FATAL, NONE. NONE means logger is diabled. Logging level can be changed programmatically or read from logger's config file (Logger.prop). Logger can write to files or standard out depending on the settings in the config file.

This Logger is designed for speed and simplicity. If you think it does not have all the functionalities you want, you can call Logger.setUseLog4j(true), so it will swith to use log4j logger, which is a powerful open source logger implementation. Some of log4j's nice features include automatically rolling over files beyond the specified size, writing the logs to the NT Event Log System or syslog daemon. Log4j jar file is not included in our products, so you need to download log4j package and add its jar file to your classpath, and in your code, you need to add a few lines to set up log4j logger. This Logger's logging levels have the same meaning as log4j's corresponding ones.

If using log4j, Logger.prop will no longer be used. You need to configure the log4j logger or provide a config file for it. You can still use the log methods in this Logger to log messages, then they will be delegated to corresponding methods in log4j logger.

A simple example of using log4j logger:

 com.ireasoning.util.Logger.setUseLog4j(true);
 com.ireasoning.util.Logger.setLevel( com.ireasoning.util.Logger.ERROR );//set level to "ERROR" 
 org.apache.log4j.BasicConfigurator.configure();//use the basic config of log4j
 


Field Summary
static String CONFIG_DIR
          config file directory, ends with "/"
static int DEBUG
          The DEBUG priority designates fine-grained informational events that are most useful to debug an application
static int ERROR
          The ERROR priority designates error events that might still allow the application to continue running.
static int FATAL
          The FATAL priority designates very severe error events that will presumably lead the application to abort.
static int INFO
          The INFO priority designates informational messages that highlight the progress of the application.
static boolean IS_EVAL
           
static String LOGGER_CONFIG_FILE
          logger's config file name
static int NONE
          No logging at all
static int WARN
          The WARN priority designates potentially harmful situations.
 
Method Summary
static void debug(Object msg)
          Logs debug level message
static void debug(Object this_ref, String mesg)
          Logs debug leve message
static void debug(Object this_ref, String name, boolean value)
          Logs debug level message, uses <name> = <value> format
static void debug(Object this_ref, String name, double value)
          Logs debug level message, uses <name> = <value> format
static void debug(Object this_ref, String name, int value)
          Logs debug level message, uses <name> = <value> format
static void debug(Object this_ref, String name, Object value)
          Logs debug level message, uses <name> = <value> format
static void debug(Object msg, Throwable e)
          Log a message object with the DEBUG level including the stack trace of the Throwable e passed as parameter.
static void debug(String name, boolean value)
          Logs debug level message, uses <name> = <value> format
static void debug(String name, double value)
          Logs debug level message, uses <name> = <value> format
static void debug(String name, int value)
          Logs debug level message, uses <name> = <value> format
static void debug(String name, String value)
          Logs debug level message, uses <name> = <value> format
static void debug(Throwable e)
          Logs the stack trace of the Throwable e passed as parameter with the DEBUG level.
static void error(Object msg)
          Log a message object with the ERROR Level.
static void error(String msg, Throwable e)
          Log a message object with the ERROR level including the stack trace of the Throwable e passed as parameter, the same as error(Throwable e, String msg)
static void error(Throwable e)
          Logs the stack trace of the Throwable e passed as parameter with the ERROR level.
static void error(Throwable e, String msg)
          Log a message object with the ERROR level including the stack trace of the Throwable e passed as parameter.
static void fatal(Object msg)
          Log a message object with the FATAL Level.
static void fatal(Object msg, Throwable e)
          Log a message object with the FATAL level including the stack trace of the Throwable e passed as parameter.
static String getLevel()
          Returns the logging level as string format
static int getLevelInt()
          Returns the logging level as integer format, one of {Logger.DEBUG, Logger.INFO, Logger.WARN, Logger.ERROR, Logger.FATAL, Logger.NONE}
static PrintStream getOutputStream(String level)
          Returns the OutputStream for the passed logging level.
static String getOutputStreamAsString(String level)
          Returns the OutputStream for the passed logging level.
static boolean getUseLog4j()
          Returns the current value set by setUseLog4j, or false if no explicit setting has been made.
static void hexDump(byte[] bytes)
          Does hex dump with the DEBUG level.
static void hexDump(byte[] bytes, int start, int end)
          Does hex dump with the DEBUG level.
static void info(Object msg)
          Log a message object with the INFO Level.
static void info(Object msg, Throwable e)
          Log a message object with the INFO level including the stack trace of the Throwable e passed as parameter.
static void setAllOutputStreams(PrintStream stream)
          Sets output stream for all logging levels
static void setLevel(int level)
          Sets new minimun logging level
static void setLevel(String level)
          Sets new minimun logging level
static void setOutputStream(String level, PrintStream stream)
          Sets the OutputStream for the passed logging level.
static void setOutputStream(String level, String stream)
          Sets the OutputStream for the passed logging level.
static void setUseLog4j(boolean b)
          Sets a flag indicating whether log4j logger should be used or not
static void setUseSlf4j(boolean b)
          Sets a flag indicating whether Slf4j logger should be used or not
static void updateLoggerConfig()
          Updates logger's config file
static void warn(Object msg)
          Log a message object with the WARN Level.
static void warn(String msg, Throwable e)
          Log a message object with the WARN level including the stack trace of the Throwable e passed as parameter.
static void warn(Throwable e)
          Logs the stack trace of the Throwable e passed as parameter with the WARN level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IS_EVAL

public static boolean IS_EVAL

CONFIG_DIR

public static final String CONFIG_DIR
config file directory, ends with "/"


LOGGER_CONFIG_FILE

public static final String LOGGER_CONFIG_FILE
logger's config file name


DEBUG

public static final int DEBUG
The DEBUG priority designates fine-grained informational events that are most useful to debug an application

See Also:
Constant Field Values

INFO

public static final int INFO
The INFO priority designates informational messages that highlight the progress of the application.

See Also:
Constant Field Values

WARN

public static final int WARN
The WARN priority designates potentially harmful situations.

See Also:
Constant Field Values

ERROR

public static final int ERROR
The ERROR priority designates error events that might still allow the application to continue running.

See Also:
Constant Field Values

FATAL

public static final int FATAL
The FATAL priority designates very severe error events that will presumably lead the application to abort.

See Also:
Constant Field Values

NONE

public static final int NONE
No logging at all

See Also:
Constant Field Values
Method Detail

setUseLog4j

public static void setUseLog4j(boolean b)
Sets a flag indicating whether log4j logger should be used or not

Parameters:
b - if true, log4j logger will be used, false to use this logger(which is the default)

setUseSlf4j

public static void setUseSlf4j(boolean b)
Sets a flag indicating whether Slf4j logger should be used or not

Parameters:
b - if true, log4j logger will be used, false to use this logger(which is the default)

getUseLog4j

public static boolean getUseLog4j()
Returns the current value set by setUseLog4j, or false if no explicit setting has been made.


setLevel

public static void setLevel(int level)
Sets new minimun logging level

Parameters:
level - one of {Logger.DEBUG, Logger.INFO, Logger.WARN, Logger.ERROR, Logger.FATAL, Logger.NONE}. NONE means no logging at all

setLevel

public static void setLevel(String level)
Sets new minimun logging level

Parameters:
level - one of {"DEBUG", "INFO", "WARN", "ERROR", "FATAL", "NONE"}, case insensitive. NONE means no logging at all

getLevel

public static String getLevel()
Returns the logging level as string format


getLevelInt

public static int getLevelInt()
Returns the logging level as integer format, one of {Logger.DEBUG, Logger.INFO, Logger.WARN, Logger.ERROR, Logger.FATAL, Logger.NONE}


fatal

public static void fatal(Object msg)
Log a message object with the FATAL Level.

Parameters:
msg - the message object to log.

fatal

public static void fatal(Object msg,
                         Throwable e)
Log a message object with the FATAL level including the stack trace of the Throwable e passed as parameter.

Parameters:
msg - the message object to log.
e - the exception to log, including its stack trace.

error

public static void error(Object msg)
Log a message object with the ERROR Level.

Parameters:
msg - the message object to log.

error

public static void error(Throwable e)
Logs the stack trace of the Throwable e passed as parameter with the ERROR level.

Parameters:
e - the exception to log, including its stack trace.

error

public static void error(String msg,
                         Throwable e)
Log a message object with the ERROR level including the stack trace of the Throwable e passed as parameter, the same as error(Throwable e, String msg)

Parameters:
msg - the message object to log.
e - the exception to log, including its stack trace.

error

public static void error(Throwable e,
                         String msg)
Log a message object with the ERROR level including the stack trace of the Throwable e passed as parameter.

Parameters:
msg - the message object to log.
e - the exception to log, including its stack trace.

hexDump

public static void hexDump(byte[] bytes)
Does hex dump with the DEBUG level.


hexDump

public static void hexDump(byte[] bytes,
                           int start,
                           int end)
Does hex dump with the DEBUG level.


debug

public static void debug(Object msg)
Logs debug level message


debug

public static void debug(String name,
                         String value)
Logs debug level message, uses <name> = <value> format


debug

public static void debug(String name,
                         int value)
Logs debug level message, uses <name> = <value> format


debug

public static void debug(String name,
                         boolean value)
Logs debug level message, uses <name> = <value> format


debug

public static void debug(String name,
                         double value)
Logs debug level message, uses <name> = <value> format


debug

public static void debug(Object this_ref,
                         String mesg)
Logs debug leve message

Parameters:
this_ref - this_ref.getClass().getName() will be written to logger
mesg - message to log

debug

public static void debug(Object this_ref,
                         String name,
                         Object value)
Logs debug level message, uses <name> = <value> format

Parameters:
this_ref - this_ref.getClass().getName() will be written to logger

debug

public static void debug(Object this_ref,
                         String name,
                         int value)
Logs debug level message, uses <name> = <value> format

Parameters:
this_ref - this_ref.getClass().getName() will be written to logger

debug

public static void debug(Object this_ref,
                         String name,
                         boolean value)
Logs debug level message, uses <name> = <value> format

Parameters:
this_ref - this_ref.getClass().getName() will be written to logger

debug

public static void debug(Object this_ref,
                         String name,
                         double value)
Logs debug level message, uses <name> = <value> format

Parameters:
this_ref - this_ref.getClass().getName() will be written to logger

debug

public static void debug(Throwable e)
Logs the stack trace of the Throwable e passed as parameter with the DEBUG level.

Parameters:
e - the exception to log, including its stack trace.

debug

public static void debug(Object msg,
                         Throwable e)
Log a message object with the DEBUG level including the stack trace of the Throwable e passed as parameter.

Parameters:
msg - the message object to log.
e - the exception to log, including its stack trace.

warn

public static void warn(String msg,
                        Throwable e)
Log a message object with the WARN level including the stack trace of the Throwable e passed as parameter.

Parameters:
msg - the message object to log.
e - the exception to log, including its stack trace.

warn

public static void warn(Throwable e)
Logs the stack trace of the Throwable e passed as parameter with the WARN level.

Parameters:
e - the exception to log, including its stack trace.

warn

public static void warn(Object msg)
Log a message object with the WARN Level.

Parameters:
msg - the message object to log.

info

public static void info(Object msg)
Log a message object with the INFO Level.

Parameters:
msg - the message object to log.

info

public static void info(Object msg,
                        Throwable e)
Log a message object with the INFO level including the stack trace of the Throwable e passed as parameter.

Parameters:
msg - the message object to log.
e - the exception to log, including its stack trace.

setOutputStream

public static void setOutputStream(String level,
                                   String stream)
Sets the OutputStream for the passed logging level.

Parameters:
level - one of {DEBUG, INFO, WARN, ERROR, FATAL, NONE}, case insensitive.
stream - "stdout", "stderr" or file name (path can be included)

setAllOutputStreams

public static void setAllOutputStreams(PrintStream stream)
Sets output stream for all logging levels


getOutputStream

public static PrintStream getOutputStream(String level)
Returns the OutputStream for the passed logging level.

Parameters:
level - one of {DEBUG, INFO, WARN, ERROR, FATAL, NONE}, case insensitive.

setOutputStream

public static void setOutputStream(String level,
                                   PrintStream stream)
Sets the OutputStream for the passed logging level.

Parameters:
level - one of {DEBUG, INFO, WARN, ERROR, FATAL, NONE}, case insensitive.
stream - output stream

getOutputStreamAsString

public static String getOutputStreamAsString(String level)
Returns the OutputStream for the passed logging level.

Parameters:
level - one of {DEBUG, INFO, WARN, ERROR, FATAL, NONE}, case insensitive.

updateLoggerConfig

public static void updateLoggerConfig()
Updates logger's config file


HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.