org.apache.tomcat.util.log
Class Log

java.lang.Object
  extended byorg.apache.tomcat.util.log.Log

public class Log
extends java.lang.Object

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.

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.

Author:
Alex Chaffee [alex@jguru.com], Costin Manolache

Field Summary
static int DEBUG
           
static int ERROR
           
static int FATAL
          Verbosity level codes.
static int INFORMATION
           
protected  java.lang.String logname
           
protected  java.lang.String prefix
           
static int WARNING
           
 
Constructor Summary
protected Log(java.lang.String channel, java.lang.String prefix, LogHandler proxy, java.lang.Object owner)
           
 
Method Summary
 void close()
           
 void flush()
          Flush any buffers.
 java.lang.String getChannel(LogManager lm)
           
 int getLevel()
          The configured logging level for this channel
static Log getLog(java.lang.String channel, java.lang.Object owner)
           
static Log getLog(java.lang.String channel, java.lang.String prefix)
           
 void log(java.lang.String msg)
          Logs the message with level INFORMATION
 void log(java.lang.String msg, int level)
          Logs the message with given level
 void log(java.lang.String prefix, java.lang.String msg, java.lang.Throwable t, int level)
           
 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))
 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
static LogManager setLogManager(LogManager lm)
          Used by the embeding application ( tomcat ) to manage the logging.
 void setProxy(LogManager lm, LogHandler l)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FATAL

public static final int FATAL
Verbosity level codes.

See Also:
Constant Field Values

ERROR

public static final int ERROR
See Also:
Constant Field Values

WARNING

public static final int WARNING
See Also:
Constant Field Values

INFORMATION

public static final int INFORMATION
See Also:
Constant Field Values

DEBUG

public static final int DEBUG
See Also:
Constant Field Values

logname

protected java.lang.String logname

prefix

protected java.lang.String prefix
Constructor Detail

Log

protected Log(java.lang.String channel,
              java.lang.String prefix,
              LogHandler proxy,
              java.lang.Object owner)
Method Detail

getLog

public static Log getLog(java.lang.String channel,
                         java.lang.String prefix)

getLog

public static Log getLog(java.lang.String channel,
                         java.lang.Object owner)

log

public void log(java.lang.String msg)
Logs the message with level INFORMATION


log

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

public void log(java.lang.String msg,
                int level)
Logs the message with given level


log

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

public void log(java.lang.String prefix,
                java.lang.String msg,
                java.lang.Throwable t,
                int level)

flush

public void flush()
Flush any buffers. Override if needed.


close

public void close()

getLevel

public int getLevel()
The configured logging level for this channel


setLogManager

public static 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.


getChannel

public java.lang.String getChannel(LogManager lm)

setProxy

public void setProxy(LogManager lm,
                     LogHandler l)


Copyright © 2001 Apache Software Foundation. All Rights Reserved.