org.openpipeline.logger
Class LoggerImpl

java.lang.Object
  extended by org.openpipeline.logger.LoggerImpl
All Implemented Interfaces:
Logger

public class LoggerImpl
extends Object
implements Logger

Provides a means of sending output to a general log file. Log files are used for reporting important system events, including searches and errors. Log files are named "prefix-yyyy-mm-dd.log" and get rolled over on a daily basis. The encoding for the output is UTF-8.


Field Summary
static String DEBUG
           
static String ERROR
           
static String INFO
           
static String WARN
           
 
Constructor Summary
LoggerImpl(String logdir, String prefix)
          Create a logger in the specified directory, and name the file starting with the specified prefix.
 
Method Summary
 void close()
          Close the log file.
 void debug(String message)
           
 void debug(String message, Throwable t)
           
 void error(String message)
           
 void error(String message, Throwable t)
           
 void info(char[] message, int offset, int len)
           
 void info(String message)
           
 void setConsole(boolean console)
          Set to true to dump log messages to the console (System.out).
 void setFlushEveryMessage(boolean flushEveryMessage)
          Set this false to allow the system to buffer messages before they are written to disk.
 void setIncludeElapsed(boolean includeElapsed)
          Set whether to include the elapsed time in milliseconds after the timestamp in each log entry.
 void setIncludeMsgType(boolean includeMsgType)
          Set whether to include the type of message in the entry, for example, "INFO", "WARN", etc.
 void setIncludeTimestamp(boolean includeTimestamp)
          Set whether to include a timestamp as the first field in each entry.
 void setLogging(boolean logging)
          Set logging on or off.
 void warn(String message)
           
 void warn(String message, Throwable t)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INFO

public static final String INFO
See Also:
Constant Field Values

WARN

public static final String WARN
See Also:
Constant Field Values

DEBUG

public static final String DEBUG
See Also:
Constant Field Values

ERROR

public static final String ERROR
See Also:
Constant Field Values
Constructor Detail

LoggerImpl

public LoggerImpl(String logdir,
                  String prefix)
Create a logger in the specified directory, and name the file starting with the specified prefix. The date and ".log" will be appended.

It's better to use LoggerFactory to get a logger instance.

Method Detail

info

public void info(char[] message,
                 int offset,
                 int len)
Specified by:
info in interface Logger

info

public void info(String message)
Specified by:
info in interface Logger

warn

public void warn(String message)
Specified by:
warn in interface Logger

warn

public void warn(String message,
                 Throwable t)
Specified by:
warn in interface Logger

debug

public void debug(String message)
Specified by:
debug in interface Logger

debug

public void debug(String message,
                  Throwable t)
Specified by:
debug in interface Logger

error

public void error(String message)
Specified by:
error in interface Logger

error

public void error(String message,
                  Throwable t)
Specified by:
error in interface Logger

close

public void close()
Close the log file.

Specified by:
close in interface Logger

setLogging

public void setLogging(boolean logging)
Set logging on or off. To turn logging off, set the parameter to false. This is useful when running the system on a read-only disc, and there is no ability to log errors or searches.

Parameters:
logging - set true to enable (default) or false to disable.

setConsole

public void setConsole(boolean console)
Set to true to dump log messages to the console (System.out). This is independent of the value set in setLogging(). If logging is off, setConsole(true) will still send messages to the console.

Parameters:
console - default is false.

setFlushEveryMessage

public void setFlushEveryMessage(boolean flushEveryMessage)
Set this false to allow the system to buffer messages before they are written to disk. Defaults to true. It's best to leave this true for error logs, because they are infrequently written and they should be committed to disk immediately so message don't get lost in the event of a crash. It's best to set this false for performance-intensive logging, like search logs. On one test computer, it took 10 seconds to write a million log entries with flushing on, and 2 seconds to write the entries with it off.


setIncludeElapsed

public void setIncludeElapsed(boolean includeElapsed)
Set whether to include the elapsed time in milliseconds after the timestamp in each log entry. Defaults to true.


setIncludeTimestamp

public void setIncludeTimestamp(boolean includeTimestamp)
Set whether to include a timestamp as the first field in each entry.


setIncludeMsgType

public void setIncludeMsgType(boolean includeMsgType)
Set whether to include the type of message in the entry, for example, "INFO", "WARN", etc.