Top Description Fields Constructors Methods
org.apache.logging.log4j.jul

public Class Log4jBridgeHandler

extends Handler
implements PropertyChangeListener
Class Inheritance
All Implemented Interfaces
java.beans.PropertyChangeListener, java.util.EventListener
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, java.beans.PropertyChangeEvent, .PropertyChangeListener, java.util.Enumeration, .HashSet, .Map, .Set, java.util.logging.LogRecord, org.apache.logging.log4j.core.LoggerContext, org.apache.logging.log4j.core.config.Configuration, org.apache.logging.log4j.core.config.LoggerConfig, org.apache.logging.log4j.spi.ExtendedLogger, org.apache.logging.log4j.status.StatusLogger

Bridge from JUL to log4j2.
This is an alternative to log4j.jul.LogManager (running as complete JUL replacement), especially useful for webapps running on a container for which the LogManager cannot or should not be used.

Installation/usage: Configuration (in JUL's logging.properties): Log levels are translated with LevelTranslator, see also log4j doc.

Restrictions: (Credits: idea and concept originate from org.slf4j.bridge.SLF4JBridgeHandler; level propagation idea originates from logback/LevelChangePropagator; but no source code has been copied)

Field Summary

Modifier and TypeField and Description
private boolean
private static final String
private volatile boolean
private static final Formatter
private Set<Logger>
julLoggerRefs

Save "hard" references to configured JUL loggers.

private String
private static final Logger
private static final String

Constructor Summary

AccessConstructor and Description
public
Log4jBridgeHandler()

Initialize this handler by reading out JUL configuration.

public
Log4jBridgeHandler(boolean debugOutput, String suffixToAppend, boolean propagateLevels)

Initialize this handler with given configuration.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract java.util.logging.Handler.close.

Close the Handler and free all associated resources.

public void
flush()

Implements abstract java.util.logging.Handler.flush.

Flush any buffered output.

private static Logger
private Logger
getLog4jLogger(final LogRecord record)

Return the log4j-Logger instance that will be used for logging.

protected void
init(boolean debugOutput, String suffixToAppend, boolean propagateLevels)

Perform init.

public static void
install(boolean
true to remove all other installed handlers on JUL root level
removeHandlersForRootLogger
,
String suffixToAppend, boolean propagateLevels)

Adds a new Log4jBridgeHandler instance to JUL's root logger.

private void
propagateLogLevels(final org.apache.logging.log4j.core.config.Configuration config)

Perform developer tests?

public void
propertyChange(final PropertyChangeEvent
A PropertyChangeEvent object describing the event source and the property that has changed.
evt
)

Implements java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

public void
publish(final LogRecord
description of the log event. A null record is silently ignored and is not published
record
)

Implements abstract java.util.logging.Handler.publish.

Publish a LogRecord.

Inherited from java.util.logging.Handler:
getEncodinggetErrorManagergetFiltergetFormattergetLevelisLoggablereportErrorsetEncodingsetErrorManagersetFiltersetFormattersetLevel

Field Detail

doDebugOutputback to summary
private boolean doDebugOutput
FQCNback to summary
private static final String FQCN
installAsLevelPropagatorback to summary
private volatile boolean installAsLevelPropagator
julFormatterback to summary
private static final Formatter julFormatter
julLoggerRefsback to summary
private Set<Logger> julLoggerRefs

Save "hard" references to configured JUL loggers. (is lazy init.)

julSuffixToAppendback to summary
private String julSuffixToAppend
SLOGGERback to summary
private static final Logger SLOGGER
UNKNOWN_LOGGER_NAMEback to summary
private static final String UNKNOWN_LOGGER_NAME

Constructor Detail

Log4jBridgeHandlerback to summary
public Log4jBridgeHandler()

Initialize this handler by reading out JUL configuration.

Log4jBridgeHandlerback to summary
public Log4jBridgeHandler(boolean debugOutput, String suffixToAppend, boolean propagateLevels)

Initialize this handler with given configuration.

Method Detail

closeback to summary
public void close()

Implements abstract java.util.logging.Handler.close.

Doc from java.util.logging.Handler.close.

Close the Handler and free all associated resources.

The close method will perform a flush and then close the Handler. After close has been called this Handler should no longer be used. Method calls may either be silently ignored or may throw runtime exceptions.

Annotations
@Override
flushback to summary
public void flush()

Implements abstract java.util.logging.Handler.flush.

Doc from java.util.logging.Handler.flush.

Flush any buffered output.

Annotations
@Override
getJulRootLoggerback to summary
private static Logger getJulRootLogger()
getLog4jLoggerback to summary
private Logger getLog4jLogger(final LogRecord record)

Return the log4j-Logger instance that will be used for logging. Handles null name case and appends configured suffix.

initback to summary
protected void init(boolean debugOutput, String suffixToAppend, boolean propagateLevels)

Perform init. of this handler with given configuration (typical use is for constructor).

Annotations
@SuppressFBWarnings:INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE
justification:The data is available only in debug mode.
installback to summary
public static void install(boolean removeHandlersForRootLogger, String suffixToAppend, boolean propagateLevels)

Adds a new Log4jBridgeHandler instance to JUL's root logger. This is a programmatic alternative to specify handlers = org.apache.logging.log4j.jul.Log4jBridgeHandler and its configuration in logging.properties.

Parameters
removeHandlersForRootLogger:boolean

true to remove all other installed handlers on JUL root level

propagateLogLevelsback to summary
private void propagateLogLevels(final org.apache.logging.log4j.core.config.Configuration config)

Perform developer tests? (Should be unused/outcommented for real code)

propertyChangeback to summary
public void propertyChange(final PropertyChangeEvent evt)

Implements java.beans.PropertyChangeListener.propertyChange.

Doc from java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

Parameters
evt:PropertyChangeEvent

A PropertyChangeEvent object describing the event source and the property that has changed.

Annotations
@Override
publishback to summary
public void publish(final LogRecord record)

Implements abstract java.util.logging.Handler.publish.

Doc from java.util.logging.Handler.publish.

Publish a LogRecord.

The logging request was made initially to a Logger object, which initialized the LogRecord and forwarded it here.

The Handler is responsible for formatting the message, when and if necessary. The formatting should include localization.

Parameters
record:LogRecord

description of the log event. A null record is silently ignored and is not published

Annotations
@Override