All Downloads are FREE. Search and download functionalities are using the official Maven repository.

manual.log4j.rst Maven / Gradle / Ivy

There is a newer version: 4.2.30
Show newest version
.. _manual-log4j:

###################
Instrumenting Log4j
###################

The ``metrics-log4j2`` module provide ``InstrumentedAppender``, a Log4j_ ``Appender`` implementation
which records the rate of logged events by their logging level. You can add it to the root logger programmatically.

.. _Log4j: https://logging.apache.org/log4j/
.. code-block:: java

    Filter filter = null;        // That's fine if we don't use filters; https://logging.apache.org/log4j/2.x/manual/filters.html
    PatternLayout layout = null; // The layout isn't used in InstrumentedAppender

    InstrumentedAppender appender = new InstrumentedAppender(metrics, filter, layout, false);
    appender.start();

    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration config = context.getConfiguration();
    config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).addAppender(appender, level, filter);
    context.updateLoggers(config);

You can also use standard log4j2 configuration, via plugin support:

.. code-block:: xml

    
    
    
        
    
    
        
            
        
    
    




© 2015 - 2025 Weber Informatics LLC | Privacy Policy