0

I am using Log4j 2 and I am using 4.0.4 version of datanucleus. When I am running my app, then it is unable to generate datanucleus logs. Datanucleus logs work fine with Log4j-1.x but when I switching Log4j-1.x to 2.x then I am unable to generate datanucleus logs.

Log4j2 XML is:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="FATAL" name="TestApp" packages="" monitorInterval="60">
  <Appenders>
    <RollingFile name="datanucleus" 
      fileName="/Test/logs/datanucleus-${sys:logging.log4j}.log"
      filePattern="/Test/logs/logs/$${date:yyyy-MM-dd}/datanucleus-${sys:logging.log4j}-%d{yyyy-MM-dd-HH}.log.gz"
      ignoreExceptions="false">
      <PatternLayout>
        <Pattern>%d{yyyy-MM-dd HH:mm:ss,SSS} %5p [%t] %C %M:%L - %m%n</Pattern>
      </PatternLayout>
      <TimeBasedTriggeringPolicy interval="24" modulate="true" />
    </RollingFile>

    <Console name="STDOUT" target="SYSTEM_OUT" ignoreExceptions="false">
      <PatternLayout pattern="%m%n" />
    </Console>
    <Failover name="Failover" primary="RollingFile">
      <Failovers>
        <AppenderRef ref="STDOUT" />
      </Failovers>
    </Failover>
  </Appenders>
  <Loggers>
    <Logger name="DataNucleus.Datastore" level="debug" additivity="false">
      <AppenderRef ref="datanucleus" />
    </Logger>
    <Logger name="DataNucleus.Cache" level="debug" additivity="false">
      <AppenderRef ref="datanucleus" />
    </Logger>
    <Logger name="DataNucleus.Persistence" level="debug" additivity="false">
      <AppenderRef ref="datanucleus" />
    </Logger>
    <Logger name="DataNucleus.Connection" level="debug" additivity="false">
      <AppenderRef ref="datanucleus" />
    </Logger>
    <Logger name="DataNucleus.Transaction" level="debug" additivity="false">
      <AppenderRef ref="datanucleus" />
    </Logger>
    <Logger name="DataNucleus.Lifecycle" level="debug" additivity="false">
      <AppenderRef ref="datanucleus" />
    </Logger>
    <Logger name="DataNucleus.MetaData" level="debug" additivity="false">
      <AppenderRef ref="datanucleus" />
    </Logger>
    <Logger name="org.datanucleus" level="debug" additivity="false">
      <AppenderRef ref="datanucleus" />
    </Logger>
    <Root level="debug">
      <AppenderRef ref="STDOUT" />
    </Root>
  </Loggers>
</Configuration>

Kindly help me on this..

With Log4j 1.2 it is working for me, but when I try with Log4j 2.3 then other logs are generated except DataNucleus logs. Here are my dependencies:

<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-api</artifactId>
  <version>2.3</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-core</artifactId>
  <version>2.3</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-slf4j-impl</artifactId>
  <version>2.3</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-web</artifactId>
  <version>2.3</version>
</dependency>
Remko Popma
  • 35,130
  • 11
  • 92
  • 114
  • I use _org.apache.logging.log4j_ "log4j-api" v2.0.1 and "log4j-core" v2.0.1 in the CLASSPATH and all works for me – Neil Stockton Aug 10 '15 at 09:04
  • Hi Neil, Thanks for your help. But i will try with your resolution and even i will try with Log4j 2.3 version also but still i am unable to generate DataNucleus logs in my application. kindly help me for this... – Sukhdev Singh Aug 10 '15 at 10:52
  • how can anyone help you when you give little to no info, and it works for us. I have log4j.properties at the root of the CLASSPATH. I use with Log4j 1.2 and it works. I change jars to Log4j 2.0.1 and it works – Neil Stockton Aug 10 '15 at 10:57
  • with Log4j 1.2 its also working for me , but when i try with log4j 2.3 then rest logs are generated except DataNucleus logs.Dependency i used are: org.apache.logging.log4j log4j-api 2.3 org.apache.logging.log4j log4j-core 2.3 org.apache.logging.log4j log4j-slf4j-impl 2.3 – Sukhdev Singh Aug 10 '15 at 11:08
  • and org.apache.logging.log4j log4j-web 2.3 – Sukhdev Singh Aug 10 '15 at 11:09

2 Answers2

0

The first thing to try is to switch on Log4j 2 internal debugging. You can do this by replacing <Configuration status="FATAL" ... at the beginning of your config file with <Configuration status="TRACE".... This will display Log4j 2 internal debugging messages to the console. If you see any error here it may help you troubleshoot the issue.

A common issue is dependencies. Does your application use the Log4j-1.2 API? If so, you need to add the log4j-1.2-api-2.3.jar bridge to your dependencies. The bridge will route all calls by your application to log4j-1.2 to the Log4j 2 implementation.

Finally, make sure you remove the log4j-1.2.x.jar from your classpath!

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
0

If you facing problem using Log4j2 with datanucleus that is because datanucleus uses legacy org.apache.log4j.Logger api . To use both log4j2 and log4j 1.x you need to use bridge method . configuring-log4j2-and-log4j-using-a-single-log4j2-xml-file

Community
  • 1
  • 1