Showing posts with label Log4j. Show all posts
Showing posts with label Log4j. Show all posts

Wednesday, April 1, 2015

log4j2: line separator in header's parameter of PatternLayout

Log4j2 provides a new parameter for PatternLayout:

Parameter name: header
Type: String
Description: the optional header string to include at the top of each log file

With the following log4j2.xml configuration:

1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="20">
    <Appenders>
        <RollingRandomAccessFile name="file" fileName="logs/app.log" filePattern="logs/app-%d_%i.log.gz">
            <PatternLayout>
                <header>
Version: ${env:APP_RELEASE_VERSION}
                </header>
                <pattern>%message%n</pattern>
            </PatternLayout>
            <Policies>
                <OnStartupTriggeringPolicy/>
            </Policies>
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="file"/>
        </Root>
    </Loggers>
</Configuration>

Saturday, July 5, 2014

JLV v.1.3.3 has been released

Update site: https://github.com/rdiachenko/jlv/raw/repo/eclipse

Or Eclipse Marketplace: http://marketplace.eclipse.org/content/jlv

Release notes:
  • fixed problems with hanging on Windows OS
  • fixed null pointer exceptions related to loading and releasing resources
  • server part was improved
  • a new resource manager was provided

    The main project's page:
     https://github.com/rdiachenko/jlv#information

    Wednesday, October 26, 2011

    Log4j: NDC/MDC

    Nested Diagnostic Context (NDC) and Mapped Diagnostic Context (MDC) are used in cases when we want to distinguish logs from multiple threads by marking each log with thread specific information. NDC and MDC provide possibility to store some contextual information for each thread. But there's a difference in the way they do it.

    Each thread has it's own context. NDC uses stack for pushing information when entering thread's context and popping it when leaving that context. This information is attached to log and can be displayed by using '%x' Pattern Layout option.

    MDC uses map to store context information. It means that there must be a unique key associated with each piece of thread information. The information is attached to log and can be displayed by using '%X{key}' Pattern Layout option, where the key is an association with a value in the map.

    Here you can find Log4j Pattern Layout option's description: http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html

    Tuesday, October 11, 2011

    How to use SLF4J with Log4j


    Today I will show you how to use SLF4J with Log4j on a simple example.

    Let's start with Log4j. First, download log4j library and add log4j-1.2.16.jar into classpath.

    Create log4j.properties file, which will contain log4j configuration and put it into project. It may look like this:

    log4j.rootLogger=DEBUG, A1
    log4j.appender.A1=org.apache.log4j.ConsoleAppender
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout
    log4j.appender.A1.layout.ConversionPattern=[%c{1}][%p]: %m%n