Log.javaAPI DocGlassfish v2 API10942Fri May 04 22:33:16 BST 2007org.apache.tomcat.util.log


public class Log extends Object implements
This 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.


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.
Commons-logging should be used instead.
Alex Chaffee []
Costin Manolache

Fields Summary
public static final int
Verbosity level codes.
public static final int
public static final int
public static final int
public static final int
protected final String
protected final String
private LogHandler
private static LogManager
Constructors Summary
protected Log(String channel, String prefix, LogHandler proxy, Object owner)

    // -------------------- Various constructors --------------------

Methods Summary
public voidclose()

public voiddebug(java.lang.Object message)

        log(message.toString(), null, DEBUG);
public voiddebug(java.lang.Object message, java.lang.Throwable exception)

        log(message.toString(), exception, DEBUG);
public voiderror(java.lang.Object message)

        log(message.toString(), null, ERROR);
public voiderror(java.lang.Object message, java.lang.Throwable exception)

        log(message.toString(), exception, ERROR);
public voidfatal(java.lang.Object message)

        log(message.toString(), null, FATAL);
public voidfatal(java.lang.Object message, java.lang.Throwable exception)

        log(message.toString(), exception, FATAL);
public voidflush()
Flush any buffers. Override if needed.

public java.lang.StringgetChannel(LogManager lm)

	if( lm != logManager ) return null;
	return logname;
public intgetLevel()
The configured logging level for this channel

	return proxy.getLevel();
public static org.apache.tomcat.util.log.LoggetLog(java.lang.String channel, java.lang.String prefix)

logname name of log to use
owner object whose class name to use as prefix

	return logManager.getLog( channel, prefix, null );
public static org.apache.tomcat.util.log.LoggetLog(java.lang.String channel, java.lang.Object owner)

logname name of log to use
prefix string to prepend to each message

	return logManager.getLog( channel, null, owner );
public voidinfo(java.lang.Object message)

        log(message.toString(), null, INFORMATION);
public voidinfo(java.lang.Object message, java.lang.Throwable exception)

        log(message.toString(), exception, INFORMATION);
public booleanisDebugEnabled()

        return proxy.getLevel() <= DEBUG;
public booleanisErrorEnabled()

        return proxy.getLevel() <= ERROR;
public booleanisFatalEnabled()

        return proxy.getLevel() <= FATAL;
public booleanisInfoEnabled()

        return proxy.getLevel() <= INFORMATION;
public booleanisTraceEnabled()

        return proxy.getLevel() <= DEBUG;
public booleanisWarnEnabled()

        return proxy.getLevel() <= WARNING;
public voidlog(java.lang.String msg)
Logs the message with level INFORMATION

	log(msg, null, INFORMATION);
public voidlog(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 voidlog(java.lang.String msg, int level)
Logs the message with given level

	log(msg, null, level);
public voidlog(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 voidlog(java.lang.String prefix, java.lang.String msg, java.lang.Throwable t, int level)

	proxy.log( prefix, msg, t, level );
public static synchronized LogManagersetLogManager(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;
	    return oldLM;
	return null;
public synchronized voidsetProxy(LogManager lm, LogHandler l)

	// only the manager can change the proxy
	if( lm!= logManager ) {
	    log("Attempt to change proxy " + lm + " " + logManager);
public voidtrace(java.lang.Object message)

        log(message.toString(), null, DEBUG);
public voidtrace(java.lang.Object message, java.lang.Throwable exception)

        log(message.toString(), exception, DEBUG);
public voidwarn(java.lang.Object message)

        log(message.toString(), null, WARNING);
public voidwarn(java.lang.Object message, java.lang.Throwable exception)

        log(message.toString(), exception, WARNING);