WebObjects 5.2.2

com.webobjects.foundation
Class NSLog.Log4JLogger

java.lang.Object
  |
  +--com.webobjects.foundation.NSLog.Logger
        |
        +--com.webobjects.foundation.NSLog.Log4JLogger
Enclosing class:
NSLog

public static class NSLog.Log4JLogger
extends NSLog.Logger

NSLog.Log4JLogger is a concrete subclass of NSLog.Logger. It logs output to an org.apache.log4j.Logger contained by this NSLog.Logger. Thisorg.apache.log4j.Logger can be changed, which causes the receiver to direct log messages.

NOTE: allowedDebugLevel is significant for any NSLog.Log4JLogger, not just an instance assigned to NSLog.debug. appendln(Object) requires a debug level internally to determine which public log method to use, because org.apache.log4j.Logger.forcedLog is protected. Make sure that you use the NSLog.Log4JLogger(int) constructor or manually invoke setAllowedDebugLevel on any new NSLog.Log4JLogger instance; this instance may fail to log output until this happens.

Verbose logging produces output of the format: [Current Time] <Current Thread Name> output

See Also:
#(int), allowedDebugLevel(), appendln(Object), setAllowedDebugLevel(int), NSLog, NSLog.Logger, NSLog.Logger.allowedDebugLevel()

Field Summary
static org.apache.log4j.Layout Log4JLoggerTerseFormat
          An org.apache.log4j.Layout roughly equivalent to the lack of a prefix.
static org.apache.log4j.Layout Log4JLoggerVerboseFormat
          An org.apache.log4j.Layout roughly equivalent to the verbose prefix provided by NSLog.PrintStreamLogger.
protected  org.apache.log4j.Logger logger
           
 
Fields inherited from class com.webobjects.foundation.NSLog.Logger
debugLevel, isEnabled, isVerbose
 
Constructor Summary
NSLog.Log4JLogger(int aDebugLevel, boolean isError)
          Creates a new NSLog.Log4JLogger.
NSLog.Log4JLogger(org.apache.log4j.Logger aLogger)
          Creates a new NSLog.Log4JLogger which directs output to aLogger.
 
Method Summary
 int allowedDebugLevel()
          Invokes getLevel().toInt() on log4jLogger, and maps the result to the equivalent NSLog debug level.
 void appendln()
          Invokes appendln(Object) with an empty string.
 void appendln(Object aValue)
          Passes aValue as the Object parameter to the appropriate method of log4jLogger, if isEnabled returns true.
protected static int convertLog4JLevelToNSLogLevel(int aLog4JDebugLevel)
           
protected static int convertNSLogLevelToLog4JLevel(int anNSLogDebugLevel)
           
 void flush()
          Does nothing.
 org.apache.log4j.Logger log4jLogger()
          Provides the org.apache.log4j.Logger wrapped by this NSLog.Log4JLogger instance.
 void setAllowedDebugLevel(int aDebugLevel)
          Passes aDebugLevel to setLevel on log4jLogger.
 void setIsVerbose(boolean aBool)
          Invokes setLayout and super.setIsVerbose(aBool).
 void setLayout(org.apache.log4j.Layout aLayout)
          Sets the org.apache.log4j.Layout for all of the org.apache.log4j.Appenders of log4jLogger.
 void setLog4jLogger(org.apache.log4j.Logger aLogger)
          Redirects output from this NSLog.Log4JLogger instance to aLogger.
 
Methods inherited from class com.webobjects.foundation.NSLog.Logger
appendln, appendln, appendln, appendln, appendln, appendln, appendln, appendln, appendln, appendln, appendln, isEnabled, isVerbose, setIsEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Log4JLoggerTerseFormat

public static final org.apache.log4j.Layout Log4JLoggerTerseFormat
An org.apache.log4j.Layout roughly equivalent to the lack of a prefix.


Log4JLoggerVerboseFormat

public static final org.apache.log4j.Layout Log4JLoggerVerboseFormat
An org.apache.log4j.Layout roughly equivalent to the verbose prefix provided by NSLog.PrintStreamLogger.


logger

protected org.apache.log4j.Logger logger
Constructor Detail

NSLog.Log4JLogger

public NSLog.Log4JLogger(int aDebugLevel,
                         boolean isError)
Creates a new NSLog.Log4JLogger. This log4jLogger will have one org.apache.log4j.ConsoleAppender which directs output to System.err or System.out, depending upon the value of isError. As the default value for isVerbose is true, as specified by NSLog.Logger(), the org.apache.log4j.ConsoleAppender instance will use NSLog.Log4JLogger.Log4JLoggerVerboseFormat. Passes aDebugLevel to setAllowedDebugLevel.

Parameters:
aDebugLevel - the debug level to use for this log4jLogger
isError - whether to direct output to System.err or System.out
Throws:
IllegalArgumentException - if setAllowedDebugLevel fails
See Also:
#(org.apache.log4j.Logger aLogger), Log4JLoggerVerboseFormat, log4jLogger(), setAllowedDebugLevel(int), NSLog.Logger#()

NSLog.Log4JLogger

public NSLog.Log4JLogger(org.apache.log4j.Logger aLogger)
Creates a new NSLog.Log4JLogger which directs output to aLogger. aLogger should be completely preconfigured. No assumptions will be made about its configuration; consequently, this constructor invokes super.setIsVerbose(false).

Throws:
IllegalArgumentException - if aLogger is null
See Also:
#(int), log4jLogger(), setIsVerbose(boolean), NSLog.Logger#()
Method Detail

allowedDebugLevel

public int allowedDebugLevel()
Invokes getLevel().toInt() on log4jLogger, and maps the result to the equivalent NSLog debug level.

This mapping is as follows:
Log4J Debug LevelNSLog Debug Level
nullDebugLevelOff
org.apache.log4j.Level.OFFDebugLevelOff
org.apache.log4j.Level.ERRORDebugLevelCritical
org.apache.log4j.Level.FATALDebugLevelCritical
org.apache.log4j.Level.INFODebugLevelInformational
org.apache.log4j.Level.WARNDebugLevelInformational
org.apache.log4j.Level.ALLDebugLevelDetailed
org.apache.log4j.Level.DEBUGDebugLevelDetailed

Overrides:
allowedDebugLevel in class NSLog.Logger
Throws:
IllegalArgumentException - if log4jLogger provides a value other than those specified in org.apache.log4j.Level
See Also:
log4jLogger(), setAllowedDebugLevel(int), NSLog.Logger.allowedDebugLevel(), NSLog

appendln

public void appendln()
Invokes appendln(Object) with an empty string.

Specified by:
appendln in class NSLog.Logger
See Also:
appendln(Object), NSLog.Logger.appendln()

appendln

public void appendln(Object aValue)
Passes aValue as the Object parameter to the appropriate method of log4jLogger, if isEnabled returns true.

Specified by:
appendln in class NSLog.Logger
Parameters:
aValue - the object to be logged
See Also:
log4jLogger(), NSLog.Logger.appendln(Object), NSLog.Logger.isEnabled

convertLog4JLevelToNSLogLevel

protected static int convertLog4JLevelToNSLogLevel(int aLog4JDebugLevel)

convertNSLogLevelToLog4JLevel

protected static int convertNSLogLevelToLog4JLevel(int anNSLogDebugLevel)

flush

public void flush()
Does nothing. org.apache.log4j.Logger does not provide a mechanism to flush output on demand. By default, org.apache.log4j.Logger does flush each fragment of output automatically.

Specified by:
flush in class NSLog.Logger
See Also:
NSLog.Logger.flush()

log4jLogger

public org.apache.log4j.Logger log4jLogger()
Provides the org.apache.log4j.Logger wrapped by this NSLog.Log4JLogger instance. The methods for this object use the org.apache.log4j.Logger instance directly, rather than via this accessor method.

Returns:
an instance of org.apache.log4j.Logger; never null
See Also:
#(int), #(org.apache.log4j.Logger), setLog4jLogger(org.apache.log4j.Logger), NSLog.Logger#()

setAllowedDebugLevel

public void setAllowedDebugLevel(int aDebugLevel)
Passes aDebugLevel to setLevel on log4jLogger. aDebugLevel may be either an NSLog debug level or an integer level from org.apache.log4j.Level. Maps an NSLog debug level to the equivalent org.apache.log4j.Level integer, or passes through a value from org.apache.log4j.Level.

This mapping is as follows:
NSLog Debug LevelLog4J Debug Level
DebugLevelOfforg.apache.log4j.Level.OFF
DebugLevelCriticalorg.apache.log4j.Level.ERROR
DebugLevelInformationalorg.apache.log4j.Level.INFO
DebugLevelDetailedorg.apache.log4j.Level.ALL

Overrides:
setAllowedDebugLevel in class NSLog.Logger
Parameters:
aDebugLevel - level of debug required
Throws:
IllegalArgumentException - if aDebugLevel is not a valid level for NSLog or org.apache.log4j.Level
See Also:
allowedDebugLevel(), log4jLogger(), NSLog.Logger.setAllowedDebugLevel(int), NSLog

setIsVerbose

public void setIsVerbose(boolean aBool)
Invokes setLayout and super.setIsVerbose(aBool). If aBool is true, passes NSLog.Log4JLogger.Log4JLoggerVerboseFormat to setLayout. Otherwise, passes NSLog.Log4JLogger.Log4JLoggerTerseFormat. This method is synchronized to avoid a race condition.

NOTE: This method has side effects described above, which vary somewhat from those described in NSLog.Logger.setIsVerbose.

Overrides:
setIsVerbose in class NSLog.Logger
Parameters:
aBool - true if NSLog.Log4JLogger.Log4JLoggerVerboseFormat should be used; false if NSLog.Log4JLogger.Log4JLoggerTerseFormat should be used
See Also:
Log4JLoggerTerseFormat, Log4JLoggerVerboseFormat, setLayout(org.apache.log4j.Layout), NSLog.Logger.isVerbose

setLayout

public void setLayout(org.apache.log4j.Layout aLayout)
Sets the org.apache.log4j.Layout for all of the org.apache.log4j.Appenders of log4jLogger. This method synchronizes on log4jLogger to avoid a race condition. No change is made if aLayout is null.

Parameters:
aLayout - an instance of org.apache.log4j.Layout
See Also:
log4jLogger()

setLog4jLogger

public void setLog4jLogger(org.apache.log4j.Logger aLogger)
Redirects output from this NSLog.Log4JLogger instance to aLogger. No change is made if aLogger is null. aLogger should be completely preconfigured. No assumptions will be made about its configuration; consequently, this constructor invokes super.setIsVerbose(false). This method synchronizes on this NSLog.Log4JLogger instance to avoid a race condition.

Parameters:
aLogger - an instance of org.apache.log4j.Logger
See Also:
#(org.apache.log4j.Logger), log4jLogger()

Last updated Mon Oct 13 15:42:52 PDT 2003.

Copyright © 2003 Apple Computer, Inc.