WebObjects 5.4.2

com.webobjects.foundation
Class NSLog.Log4JLogger

java.lang.Object
  extended by com.webobjects.foundation.NSLog.Logger
      extended by 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.

Since:
5.2.2
See Also:
NSLog.Log4JLogger.allowedDebugLevel(), NSLog.Log4JLogger.appendln(Object), NSLog.Log4JLogger.setAllowedDebugLevel(int), NSLog, NSLog.Logger, NSLog.Logger.allowedDebugLevel()

Field Summary
protected  org.apache.log4j.Logger logger
           
protected  org.apache.log4j.Level logLevel
           
 
Fields inherited from class com.webobjects.foundation.NSLog.Logger
debugLevel, isEnabled, isVerbose
 
Constructor Summary
NSLog.Log4JLogger()
           
NSLog.Log4JLogger(org.apache.log4j.Logger aLogger, int level)
          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 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, setIsVerbose
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.apache.log4j.Logger logger

logLevel

protected org.apache.log4j.Level logLevel
Constructor Detail

NSLog.Log4JLogger

public NSLog.Log4JLogger()

NSLog.Log4JLogger

public NSLog.Log4JLogger(org.apache.log4j.Logger aLogger,
                         int level)
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:
NSLog.Log4JLogger.log4jLogger(), NSLog.Logger.setIsVerbose(boolean), NSLog.Logger
Method Detail

convertLog4JLevelToNSLogLevel

protected static int convertLog4JLevelToNSLogLevel(int aLog4JDebugLevel)

convertNSLogLevelToLog4JLevel

protected static int convertNSLogLevelToLog4JLevel(int anNSLogDebugLevel)

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 Level NSLog Debug Level
null DebugLevelOff
org.apache.log4j.Level.OFF DebugLevelOff
org.apache.log4j.Level.ERROR DebugLevelCritical
org.apache.log4j.Level.FATAL DebugLevelCritical
org.apache.log4j.Level.INFO DebugLevelInformational
org.apache.log4j.Level.WARN DebugLevelInformational
org.apache.log4j.Level.ALL DebugLevelDetailed
org.apache.log4j.Level.DEBUG DebugLevelDetailed

Overrides:
allowedDebugLevel in class NSLog.Logger
Returns:
one of the debug levels specified in NSLog
Throws:
IllegalArgumentException - if log4jLogger provides a value other than those specified in org.apache.log4j.Level
See Also:
NSLog.Log4JLogger.log4jLogger(), NSLog.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:
NSLog.Log4JLogger.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:
NSLog.Log4JLogger.log4jLogger(), NSLog.Logger.appendln(Object), NSLog.Logger.isEnabled

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:
NSLog.Log4JLogger.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 Level Log4J Debug Level
DebugLevelOff org.apache.log4j.Level.OFF
DebugLevelCritical org.apache.log4j.Level.ERROR
DebugLevelInformational org.apache.log4j.Level.INFO
DebugLevelDetailed org.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
See Also:
NSLog.Log4JLogger.allowedDebugLevel(), NSLog.Log4JLogger.log4jLogger(), NSLog.Logger.setAllowedDebugLevel(int), NSLog

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;.

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

Last updated June 2008

Copyright © 2000-2008 Apple Inc.