## org.apache.jasper.logging
Class Logger.Helper

    java.lang.Object
      |
      +--org.apache.jasper.logging.Logger.Helper

All Implemented Interfaces:
  LogAware

Enclosing class:
  Logger

public static class Logger.Helper
extends java.lang.Object
implements LogAware

Wrapper for Logger. It has a preferred log name 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. Not intended to supplant Logger, but to allow client objects a consistent bit of code that prepares log messages before they reach logger (and does the right thing if there is no logger).

Usage:

     class Foo {
       Logger.Helper loghelper = new Logger.Helper("tc_log", "Foo"); // or...
       Logger.Helper loghelper = new Logger.Helper("tc_log", this); // fills in "Foo" for you
       ...
         loghelper.log("Something happened");
         ...
         loghelper.log("Starting something", Logger.DEBUG);
         ...
         catch (IOException e) {
           loghelper.log("While doing something", e);
         }

Author:
  Alex Chaffee [alex@jguru.com]

Constructor Summary
`protected` `Logger.Helper(java.lang.String logname)` Subclass constructor, for classes that want to *be* a LogHelper, and get the log methods for free (like a mixin)
`` `Logger.Helper(java.lang.String logname, java.lang.Object owner)`
`` `Logger.Helper(java.lang.String logname, java.lang.String prefix)`

Method Summary
`Logger` `getLogger()`
`Logger.Helper` `getLoggerHelper()`
`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 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
`void` `setLogger(Logger logger)` Set a logger explicitly.
`void` `setLogname(java.lang.String logname)` Set the logger by name.
`void` `setLogPrefix(java.lang.String prefix)` Set the prefix string to be prepended to each message
`void` `setProxy(Logger.Helper helper)` Set a "proxy" Logger.Helper -- whatever that one says its Logger is, use it

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Logger.Helper

    protected Logger.Helper(java.lang.String logname)

  Subclass constructor, for classes that want to *be* a LogHelper, and get the log methods for free (like a mixin)

### Logger.Helper

    public Logger.Helper(java.lang.String logname,
                         java.lang.Object owner)

Parameters:
  `logname` - name of log to use
  `owner` - object whose class name to use as prefix

### Logger.Helper

    public Logger.Helper(java.lang.String logname,
                         java.lang.String prefix)

Parameters:
  `logname` - name of log to use
  `prefix` - string to prepend to each message

Method Detail

### getLogger

    public Logger getLogger()

### setLogger

    public void setLogger(Logger logger)

  Set a logger explicitly. Also resets the logname property to match that of the given log.

  (Note that setLogger(null) will not necessarily redirect log output to System.out; if there is a logger named logname it will fall back to using it, or trying to.)

  Specified by:
    `setLogger` in interface `LogAware`

### setLogname

    public void setLogname(java.lang.String logname)

  Set the logger by name. Will throw away current idea of what its logger is, and next time it's asked, will locate the global Logger object if the given name.

### setLogPrefix

    public void setLogPrefix(java.lang.String prefix)

  Set the prefix string to be prepended to each message

### setProxy

    public void setProxy(Logger.Helper helper)

  Set a "proxy" Logger.Helper -- whatever that one says its Logger is, use it

### getLoggerHelper

    public Logger.Helper getLoggerHelper()

  Specified by:
    `getLoggerHelper` in interface `LogAware`

### 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

Copyright © 2000 Apache Software Foundation. All Rights Reserved.