Logging Spring using Log4j2

I am trying to use Log4j2 to print the spring logs into a file and console. I guess it is a problem of my Log4j2 configuration, but I have not been able to get it working. I have this configuration in my log4j2.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration name="defaultConfiguration" status="warn" strict="true" monitorInterval="5">
    <properties>
        <property name="patternlayout">%d{ISO8601} [%t] %-5level %logger{36} - %msg%n%throwable{full}</property>
        <property name="filename">${env:MY_ROOT}/logs/mylog.log</property>
        <property name="filenamePattern">${env:MY_ROOT}/logs/mylog-%d{yyyy-dd-MM}-%i.log.gz</property>
    </properties>
    <appenders>
        <appender name="Console" type="Console" target="SYSTEM_OUT">
            <layout type="PatternLayout" pattern="${patternlayout}" />
        </appender>
        <appender name="File" type="RollingFile" fileName="${filename}" filePattern="${filenamePattern}" bufferedIO="true" immediateFlush="true"
        append="true">
            <layout type="PatternLayout" pattern="${patternlayout}" />
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="50 MB" />
            </Policies>
            <DefaultRolloverStrategy max="30" />
        </appender>
        <appender name="AsynchFile" type="asynch" blocking="true" bufferSize="128">
            <appender-ref ref="File" />
        </appender>
    </appenders>
    <loggers>
        <root level="info">
            <appender-ref ref="Console" />
            <appender-ref ref="AsynchFile" />
        </root>
        <logger name="org.springframework.beans">
            <appender-ref ref="Console" />
            <appender-ref ref="AsynchFile" />
        </logger>
    </loggers>
</configuration>

This is the dependencies that I have in my pom file: (probably some of them are not required)

<dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-api</artifactId>
 <version>1.6.6</version>
</dependency>

<dependency>
 <groupId>org.slf4j</groupId>
 <artifactId>slf4j-log4j12</artifactId>
 <version>1.6.6</version>
</dependency>

<dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-api</artifactId>
 <version>2.0-beta5</version>
</dependency>

<dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-core</artifactId>
 <version>2.0-beta5</version>
</dependency>
<dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-1.2-api</artifactId>
 <version>2.0-beta5</version>
</dependency>

<dependency>
 <groupId>com.lmax</groupId>
 <artifactId>disruptor</artifactId>
 <version>3.0.0.beta3</version>
</dependency>

I am not doing anything related to spring in my Java code. I am using the Main class from Apache Camel which reads my spring configuration and loads the beans.

What am I doing wrong? Thanks!

Edit: I am not getting spring logs in any output (console or file). However, I am able to get the logs I create in my java code. I hope this clarification would help.

Answers


Looking at the dependencies in your pom, you have this one: slf4j-log4j12. This causes log statements against the slf4j api to be routed to the Log4j-1.2 implementation. You probably want these to be routed to the Log4j-2.0 implementation. Can you replace slf4j-log4j12 with log4j-slf4j-impl and try again?


Need Your Help

Detect when I'm leaving a frame in ActionsScript 3.0?

flash actionscript flash-cs3

Is there an event listener to use to detect whenever I am leaving a particular frame on my timeline?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.