Logpublic class Log extends Object implements com.sun.org.apache.commons.logging.LogThis is the main class seen by objects that need to log.
It has a log channel to write to; if it can't find a log with that name,
it outputs to the default
sink. Also prepends a descriptive name to each message
(usually the toString() of the calling object), so it's easier
to identify the source.
Intended for use by client classes to make it easy to do
reliable, consistent logging behavior, even if you don't
necessarily have a context, or if you haven't registered any
log files yet, or if you're in a non-Tomcat application.
Usage:
class Foo {
Log log = Log.getLog("tc_log", "Foo"); // or...
Log log = Log.getLog("tc_log", this); // fills in "Foo" for you
...
log.log("Something happened");
...
log.log("Starting something", Log.DEBUG);
...
catch (IOException e) {
log.log("While doing something", e);
}
As a special feature ( required in tomcat operation ) the
Log can be modified at run-time, by changing and configuring the logging
implementation ( without requiring any special change in the user code ).
That means that the user can do a Log.getLog() at any time,
even before the logging system is fully configured. The
embeding application can then set up or change the logging details,
without any action from the log user. |
Fields Summary |
---|
public static final int | FATALVerbosity level codes. | public static final int | ERROR | public static final int | WARNING | public static final int | INFORMATION | public static final int | DEBUG | protected final String | logname | protected final String | prefix | private LogHandler | proxy | private static LogManager | logManager |
Constructors Summary |
---|
protected Log(String channel, String prefix, LogHandler proxy, Object owner)
// -------------------- Various constructors --------------------
this.logname=channel;
this.prefix=prefix;
this.proxy=proxy;
|
Methods Summary |
---|
public void | close()
proxy.close();
| public void | debug(java.lang.Object message)
log(message.toString(), null, DEBUG);
| public void | debug(java.lang.Object message, java.lang.Throwable exception)
log(message.toString(), exception, DEBUG);
| public void | error(java.lang.Object message)
log(message.toString(), null, ERROR);
| public void | error(java.lang.Object message, java.lang.Throwable exception)
log(message.toString(), exception, ERROR);
| public void | fatal(java.lang.Object message)
log(message.toString(), null, FATAL);
| public void | fatal(java.lang.Object message, java.lang.Throwable exception)
log(message.toString(), exception, FATAL);
| public void | flush()Flush any buffers.
Override if needed.
proxy.flush();
| public java.lang.String | getChannel(LogManager lm)
if( lm != logManager ) return null;
return logname;
| public int | getLevel()The configured logging level for this channel
return proxy.getLevel();
| public static org.apache.tomcat.util.log.Log | getLog(java.lang.String channel, java.lang.String prefix)
return logManager.getLog( channel, prefix, null );
| public static org.apache.tomcat.util.log.Log | getLog(java.lang.String channel, java.lang.Object owner)
return logManager.getLog( channel, null, owner );
| public void | info(java.lang.Object message)
log(message.toString(), null, INFORMATION);
| public void | info(java.lang.Object message, java.lang.Throwable exception)
log(message.toString(), exception, INFORMATION);
| public boolean | isDebugEnabled()
return proxy.getLevel() <= DEBUG;
| public boolean | isErrorEnabled()
return proxy.getLevel() <= ERROR;
| public boolean | isFatalEnabled()
return proxy.getLevel() <= FATAL;
| public boolean | isInfoEnabled()
return proxy.getLevel() <= INFORMATION;
| public boolean | isTraceEnabled()
return proxy.getLevel() <= DEBUG;
| public boolean | isWarnEnabled()
return proxy.getLevel() <= WARNING;
| public void | log(java.lang.String msg)Logs the message with level INFORMATION
log(msg, null, INFORMATION);
| public void | log(java.lang.String msg, java.lang.Throwable t)Logs the Throwable with level ERROR (assumes an exception is
trouble; if it's not, use log(msg, t, level))
log(msg, t, ERROR);
| public void | log(java.lang.String msg, int level)Logs the message with given level
log(msg, null, level);
| public void | log(java.lang.String msg, java.lang.Throwable t, int level)Logs the message and Throwable to its logger or, if logger
not found, to the default logger, which writes to the
default sink, which is usually System.err
log( prefix, msg, t, level );
| public void | log(java.lang.String prefix, java.lang.String msg, java.lang.Throwable t, int level)
proxy.log( prefix, msg, t, level );
| public static synchronized LogManager | setLogManager(LogManager lm)Used by the embeding application ( tomcat ) to manage
the logging.
Initially, the Log is not managed, and the default
manager is used. The application can find what loggers
have been created from the default LogManager, and
provide a special manager implemetation.
// can be changed only once - so that user
// code can't change the log manager in running servers
if( logManager.getClass() == LogManager.class ) {
LogManager oldLM=logManager;
logManager=lm;
return oldLM;
}
return null;
| public synchronized void | setProxy(LogManager lm, LogHandler l)
// only the manager can change the proxy
if( lm!= logManager ) {
log("Attempt to change proxy " + lm + " " + logManager);
return;
}
proxy=l;
| public void | trace(java.lang.Object message)
log(message.toString(), null, DEBUG);
| public void | trace(java.lang.Object message, java.lang.Throwable exception)
log(message.toString(), exception, DEBUG);
| public void | warn(java.lang.Object message)
log(message.toString(), null, WARNING);
| public void | warn(java.lang.Object message, java.lang.Throwable exception)
log(message.toString(), exception, WARNING);
|
|