|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.hp.hpl.jena.util.Log
Simple logging abstraction for use within the Jena core. We have a general need to
log debug and diagnostic information, but we don't want to introduce another
dependency for Jena users by building on, say, Log4J (good though that package is).
Furthermore, the upcoming JDK 1.4 release will contain a standard logging API
java.util.logging
. We won't standardise on this API, since that would
require all Jena users to upgrade to a new JDK release. However, this class is
designed so that users who want to can interface this simple logger to more
sophisticated mechanisms, including the new standard.
Following common practice among logging packages, a number of levels of
severity are defined. Each log call is at one of these levels, and the logger has
a state variable that indicates the lowest level it will accept. Log entries at
this level or higher will be logged, those below this level will be silently
ignored. The levels are taken from the new java.util.logging
API:
While the JDK 1.4 logger contains a great deal of flexibility for directing output
to different destinations, formatting, and localising, this class has deliberately
much simpler capabilities. A log handler interface is defined (see
LogHandler
), which can publish a log message
as it sees fit. This logger supports the use of a single log handler at a time, which
will consume all log messages. Two standard handlers are defined, one for console
output via System.err
, and one for outputting to a file. However, another
log handler, with arbitrary formatting capability, can be defined via setHandler(com.hp.hpl.jena.util.LogHandler)
.
There is one global logger, implemented via a singleton pattern. Convenience static methods are provided for programmers to have simple access to logging capability.
Basic usage patterns:
Log a warning to the default output (console):
Direct log output to a file, and log a severe level exception (with stacktrace):
Log.warning( "Frimble count below threshold: " + nFrimbles );
Debug output, without timestamp:
Log.getInstance().setDefaultFileHandler();
Log.severe( "IOException while frimbling: " + frimEx, frimEx );
Log.getInstance().setShowDate( false );
Log.getInstance().setLevel( Log.FINE );
Log.debug( "Frimble count: " + nFrimbles,
Frimbler.class.getName(), "countFrimbles" );
Field Summary | |
static int |
CONFIG
Message level, representing the level below INFO |
static int |
DEBUG
Convenience alias for FINE |
static int |
DEFAULT_LEVEL
The default message level for the logger (CONFIG) |
static java.lang.String |
DEFAULT_LOG_FILE_NAME
The default file name for the Jena log file |
static int |
FINE
Message level, representing the level below CONFIG |
static int |
FINER
Message level, representing the level below FINE |
static int |
FINEST
Message level, representing the lowest level (least important) messages |
static int |
INFO
Message level, representing the level below WARNING |
static java.lang.String[] |
LEVEL_NAMES
Set of names corresponding to the well-known levels |
static int |
OFF
Message level used to suppress all messages. |
static int |
SEVERE
Message level, representing the highest level (most important) messages |
static int |
WARNING
Message level, representing the level below SEVERE |
Method Summary | |
static void |
config(java.lang.String msg)
Log the given message at log level CONFIG . |
static void |
config(java.lang.String msg,
java.lang.String cls,
java.lang.String method)
Log the given message at log level CONFIG . |
static void |
config(java.lang.String msg,
java.lang.String cls,
java.lang.String method,
java.lang.Throwable ex)
Log the given message at log level CONFIG . |
static void |
config(java.lang.String msg,
java.lang.Throwable ex)
Log the given message at log level CONFIG . |
static void |
debug(java.lang.String msg)
Log the given message at log level DEBUG (alias FINE). |
static void |
debug(java.lang.String msg,
java.lang.String cls,
java.lang.String method)
Log the given message at log level DEBUG (alias FINE). |
static void |
debug(java.lang.String msg,
java.lang.String cls,
java.lang.String method,
java.lang.Throwable ex)
Log the given message at log level DEBUG (alias FINE). |
static void |
debug(java.lang.String msg,
java.lang.Throwable ex)
Log the given message at log level DEBUG (alias FINE). |
static void |
fine(java.lang.String msg)
Log the given message at log level FINE . |
static void |
fine(java.lang.String msg,
java.lang.String cls,
java.lang.String method)
Log the given message at log level FINE . |
static void |
fine(java.lang.String msg,
java.lang.String cls,
java.lang.String method,
java.lang.Throwable ex)
Log the given message at log level FINE . |
static void |
fine(java.lang.String msg,
java.lang.Throwable ex)
Log the given message at log level FINE . |
static void |
finer(java.lang.String msg)
Log the given message at log level FINER . |
static void |
finer(java.lang.String msg,
java.lang.String cls,
java.lang.String method)
Log the given message at log level FINER . |
static void |
finer(java.lang.String msg,
java.lang.String cls,
java.lang.String method,
java.lang.Throwable ex)
Log the given message at log level FINER . |
static void |
finer(java.lang.String msg,
java.lang.Throwable ex)
Log the given message at log level FINER . |
static void |
finest(java.lang.String msg)
Log the given message at log level FINEST . |
static void |
finest(java.lang.String msg,
java.lang.String cls,
java.lang.String method)
Log the given message at log level FINEST . |
static void |
finest(java.lang.String msg,
java.lang.String cls,
java.lang.String method,
java.lang.Throwable ex)
Log the given message at log level FINEST . |
static void |
finest(java.lang.String msg,
java.lang.Throwable ex)
Log the given message at log level FINEST . |
static java.lang.String |
formatDate()
Answer a string representing the date and time, formatted for output to the console. |
static Log |
getInstance()
Answer a reference to the singleton (global) instance of the logger. |
int |
getLevel()
Answer the current logging level. |
static java.lang.String |
getLevelName(int level)
Answer a readable string for the given level identifier |
boolean |
getShowDate()
Answer whether the date is shown in console output. |
static void |
info(java.lang.String msg)
Log the given message at log level INFO . |
static void |
info(java.lang.String msg,
java.lang.String cls,
java.lang.String method)
Log the given message at log level INFO . |
static void |
info(java.lang.String msg,
java.lang.String cls,
java.lang.String method,
java.lang.Throwable ex)
Log the given message at log level INFO . |
static void |
info(java.lang.String msg,
java.lang.Throwable ex)
Log the given message at log level INFO . |
void |
setConsoleHandler()
Set the current output handler to one that writes to System.err |
void |
setDefaultFileHandler()
Set the current output handler to one that writes to the default log file (see DEFAULT_LOG_FILE_NAME ), overwriting any
existing contents. |
void |
setDefaultFileHandler(boolean append)
Set the current output handler to one that writes to the default log file (see DEFAULT_LOG_FILE_NAME ), optionally appending
to any existing log file contents. |
void |
setFileHandler(java.lang.String fileName)
Set the current output handler to one that writes to the given file, overwriting the current contents, if any. |
void |
setFileHandler(java.lang.String fileName,
boolean append)
Set the current output handler to one that writes to the given file, optionally appending to the existing contents of the logfile. |
void |
setHandler(LogHandler handler)
Set the current output handler to be the given object. |
void |
setLevel(int level)
Set the current loggin level to the given value. |
void |
setShowDate(boolean showDate)
Set a flag to control whether the date is shown in the console log. |
static void |
severe(java.lang.String msg)
Log the given message at log level SEVERE . |
static void |
severe(java.lang.String msg,
java.lang.String cls,
java.lang.String method)
Log the given message at log level SEVERE . |
static void |
severe(java.lang.String msg,
java.lang.String cls,
java.lang.String method,
java.lang.Throwable ex)
Log the given message at log level SEVERE . |
static void |
severe(java.lang.String msg,
java.lang.Throwable ex)
Log the given message at log level SEVERE . |
static void |
warning(java.lang.String msg)
Log the given message at log level WARNING . |
static void |
warning(java.lang.String msg,
java.lang.String cls,
java.lang.String method)
Log the given message at log level WARNING . |
static void |
warning(java.lang.String msg,
java.lang.String cls,
java.lang.String method,
java.lang.Throwable ex)
Log the given message at log level WARNING . |
static void |
warning(java.lang.String msg,
java.lang.Throwable ex)
Log the given message at log level WARNING . |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int SEVERE
public static final int WARNING
public static final int INFO
public static final int CONFIG
public static final int FINE
public static final int FINER
public static final int FINEST
public static final int OFF
public static final int DEBUG
public static final java.lang.String DEFAULT_LOG_FILE_NAME
public static final int DEFAULT_LEVEL
public static final java.lang.String[] LEVEL_NAMES
Method Detail |
public static final Log getInstance()
public void setLevel(int level)
level
- The new logging levelpublic int getLevel()
public static java.lang.String getLevelName(int level)
level
- The level numberpublic void setHandler(LogHandler handler)
handler
- The new output handler.public void setDefaultFileHandler() throws java.io.IOException
DEFAULT_LOG_FILE_NAME
), overwriting any
existing contents.Throws
- IOException if the default log file cannot be opened for writing.public void setDefaultFileHandler(boolean append) throws java.io.IOException
DEFAULT_LOG_FILE_NAME
), optionally appending
to any existing log file contents.append
- If true, append to the end of the existing log file; otherwise
overwrite it.Throws
- IOException if the default log file cannot be opened for writing.public void setFileHandler(java.lang.String fileName) throws java.io.IOException
fileName
- The name of the file to write to.java.io.IOException
- if the file cannot be opened for writing.public void setFileHandler(java.lang.String fileName, boolean append) throws java.io.IOException
fileName
- The name of the file to write to.append
- If true, append to the end of the file; otherwise overwrite it.java.io.IOException
- if the file cannot be opened for writing.public void setConsoleHandler()
public void setShowDate(boolean showDate)
showDate
- If true, the date and time will be prepended to console log output.public boolean getShowDate()
public static java.lang.String formatDate()
public static void severe(java.lang.String msg)
SEVERE
.msg
- The message textpublic static void severe(java.lang.String msg, java.lang.Throwable ex)
SEVERE
.msg
- The message text.ex
- A throwable (exception or error) that triggered the log event.public static void severe(java.lang.String msg, java.lang.String cls, java.lang.String method)
SEVERE
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventpublic static void severe(java.lang.String msg, java.lang.String cls, java.lang.String method, java.lang.Throwable ex)
SEVERE
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventex
- A throwable (exception or error) that triggered the log event.public static void warning(java.lang.String msg)
WARNING
.msg
- The message textpublic static void warning(java.lang.String msg, java.lang.Throwable ex)
WARNING
.msg
- The message text.ex
- A throwable (exception or error) that triggered the log event.public static void warning(java.lang.String msg, java.lang.String cls, java.lang.String method)
WARNING
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventpublic static void warning(java.lang.String msg, java.lang.String cls, java.lang.String method, java.lang.Throwable ex)
WARNING
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventex
- A throwable (exception or error) that triggered the log event.public static void info(java.lang.String msg)
INFO
.msg
- The message textpublic static void info(java.lang.String msg, java.lang.Throwable ex)
INFO
.msg
- The message text.ex
- A throwable (exception or error) that triggered the log event.public static void info(java.lang.String msg, java.lang.String cls, java.lang.String method)
INFO
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventpublic static void info(java.lang.String msg, java.lang.String cls, java.lang.String method, java.lang.Throwable ex)
INFO
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventex
- A throwable (exception or error) that triggered the log event.public static void config(java.lang.String msg)
CONFIG
.msg
- The message textpublic static void config(java.lang.String msg, java.lang.Throwable ex)
CONFIG
.msg
- The message text.ex
- A throwable (exception or error) that triggered the log event.public static void config(java.lang.String msg, java.lang.String cls, java.lang.String method)
CONFIG
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventpublic static void config(java.lang.String msg, java.lang.String cls, java.lang.String method, java.lang.Throwable ex)
CONFIG
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventex
- A throwable (exception or error) that triggered the log event.public static void fine(java.lang.String msg)
FINE
.msg
- The message textpublic static void fine(java.lang.String msg, java.lang.Throwable ex)
FINE
.msg
- The message text.ex
- A throwable (exception or error) that triggered the log event.public static void fine(java.lang.String msg, java.lang.String cls, java.lang.String method)
FINE
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventpublic static void fine(java.lang.String msg, java.lang.String cls, java.lang.String method, java.lang.Throwable ex)
FINE
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventex
- A throwable (exception or error) that triggered the log event.public static void finer(java.lang.String msg)
FINER
.msg
- The message textpublic static void finer(java.lang.String msg, java.lang.Throwable ex)
FINER
.msg
- The message text.ex
- A throwable (exception or error) that triggered the log event.public static void finer(java.lang.String msg, java.lang.String cls, java.lang.String method)
FINER
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventpublic static void finer(java.lang.String msg, java.lang.String cls, java.lang.String method, java.lang.Throwable ex)
FINER
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventex
- A throwable (exception or error) that triggered the log event.public static void finest(java.lang.String msg)
FINEST
.msg
- The message textpublic static void finest(java.lang.String msg, java.lang.Throwable ex)
FINEST
.msg
- The message text.ex
- A throwable (exception or error) that triggered the log event.public static void finest(java.lang.String msg, java.lang.String cls, java.lang.String method)
FINEST
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventpublic static void finest(java.lang.String msg, java.lang.String cls, java.lang.String method, java.lang.Throwable ex)
FINEST
.msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventex
- A throwable (exception or error) that triggered the log event.public static void debug(java.lang.String msg)
DEBUG
(alias FINE).msg
- The message textpublic static void debug(java.lang.String msg, java.lang.Throwable ex)
DEBUG
(alias FINE).msg
- The message text.ex
- A throwable (exception or error) that triggered the log event.public static void debug(java.lang.String msg, java.lang.String cls, java.lang.String method)
DEBUG
(alias FINE).msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventpublic static void debug(java.lang.String msg, java.lang.String cls, java.lang.String method, java.lang.Throwable ex)
DEBUG
(alias FINE).msg
- The message text.cls
- The class name of the originator of the log eventmethod
- The method name of the originator of the log eventex
- A throwable (exception or error) that triggered the log event.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |