Unable to generate logs of datanucleus using log4j 2.0 - log4j2

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>

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

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!

Related

log4j:WARN No appenders could be found for logger (org.apache.hc.client5.http.impl.classic.InternalHttpClient)

I've implemented a simple Java app that uses httpclient 5.1.3. I'm also using log4j2 (2.1.9) and have configured it emit log entries at the wire level. I know the log4j2 config is loaded because I can see my file appender working when I emit log messages from my app.
I don't understand why httpclient logging reports no appenders for org.apache.hc.client5.http.impl.classic.InternalHttpClient or for the asynch class if I change my app to use asynch protocol. Please help.
My log4j2 config:
<Appenders>
<Console name="Console">
<PatternLayout pattern="%d %-5level [%logger] %msg%n%xThrowable" />
</Console>
<File name="MyFile" fileName="c:/a/app.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</File>
</Appenders>
<Loggers>
<Logger name="org.apache.hc.client5.http" level="DEBUG">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="org.apache.hc.client5.http.wire" level="DEBUG">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="org.apache.hc.client5.http.impl.classic.InternalHttpClient" level="DEBUG">
<AppenderRef ref="Console"/>
</Logger>
<Root level="INFO">
<AppenderRef ref="MyFile" />
</Root>
</Loggers>
</Configuration>
I could sure use some help. Thanks.

Server Logs not showing with log4j2

When I migrate from log4j to log4j2 Server Logs not showing.
Log4j2.xml exist in classpath.
here is my log4j2.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" packages="com.vermeg.maskpolicy.customLog" monitorInterval="5">
<Appenders>
<RollingFile name="FILE" fileName="${soliam.fo.logdir}/log/server.log" append="true"
filePattern="${soliam.fo.logdir}/log/$${date:yyyy-MM}/server-%d{yyyy-MM-dd}.log">
<PatternLayout pattern="%d %-5p %X{userName}#%X{remoteAddress} [%c] %m%n"/>
<ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
<CronTriggeringPolicy schedule="0 0 0 * * ?"/>
</RollingFile>
<Console name="CONSOLE" target="SYSTEM_OUT">
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="%d{ABSOLUTE} %-5p %X{userName}#%X{remoteAddress} [%c{1}] %m%n"/>
</Console>
<Rewrite name="rewrite">
<LogInterceptor/>
<AppenderRef ref="CONSOLE"/>
<AppenderRef ref="FILE"/>
</Rewrite>
</Appenders>
<Loggers>
<Logger name="com.bsb.soliam.fo.aspectj.AspectJLogger" level="${log4j.level}">
<AppenderRef ref="rewrite"/>
</Logger>
<Logger name="org.jgroups" level="WARN">
<AppenderRef ref="rewrite"/>
</Logger>
<Logger name="org.apache.cxf.phase.PhaseInterceptorChain" level="ERROR">
<AppenderRef ref="rewrite"/>
</Logger>
<Logger name="org.springframework.flex.servlet.MessageBrokerHandlerAdapter" level="WARN">
</Logger>
<Logger name="org.apache.commons.javaflow" level="INFO">
</Logger>
<Logger name="org.apache.commons.beanutils.locale" level="INFO">
</Logger>
<Logger name="com.bsb.soliam.fo.core.filepoller.JmsJobScheduler" additivity="false" level="${log4j.level}">
<AppenderRef ref="rewrite"/>
</Logger>
<Root level="${log4j.root.level}">
<AppenderRef ref="rewrite"/>
</Root>
</Loggers>
</Configuration>
log before migration
enter image description here
log after migration just show hibernate log.
I don't know the main cause of this problem ,
can anyone help please

log4j2 config file not logging to console/file

I have the following log4j2.xml config that I am using.
I have 2 issues :-
When my application runs up, I have nothing logged to either the
console or to mylog.log file by either of apache or springframework or
hibernate classes.
Classes within the package "com.foo.bar", I am able change the log
LEVEL via "level" attribute but the messages are only logged to
mylog.log file but nothing to the console
Any suggestions to above would be appreciated ?
thank you
Pete
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{DEFAULT} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<RollingFile name="File" fileName="mylog.log"
filePattern="mylog-%d{yyyy-MM-dd}.%i.log">
<PatternLayout pattern="%d{DEFAULT} [%t] %-5level %logger{36} - %msg%n" />
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="30 MB" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.foo.bar" level="info" additivity="false">
<AppenderRef ref="File" />
<AppenderRef ref="Console" />
</Logger>
<Logger name="org.apache" level="debug" >
<AppenderRef ref="File" />
<AppenderRef ref="Console" />
</Logger>
<Logger name="org.hibernate" level="debug" additivity="false">
<AppenderRef ref="File" />
</Logger>
<Logger name="org.springframework" level="debug" additivity="false">
<AppenderRef ref="File" />
</Logger>
<Root level="all">
<AppenderRef ref="Console" />
<AppenderRef ref="File" />
</Root>
</Loggers>
Please try replacing
<Root level="all">
With
<Root level="trace">
It sounds like you have a misconfigured log.
Can you debug remotely and where you find use the logger to log something place a breakpoint. Inspect the logger and then you will find a location of where its picking up the log file from.
Also try providing a VM argument for log4j configuration (-Dlog4j.configuration)on start-up of your application.

log4j2 RollingFile with 3 policies

I am using log4j2 version 2.7 with sprint-boot 1.5:
my configuration file (log4j2.xml) is:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="60">
<Properties>
<Property name="LOG_PATH">./log</Property>
<Property name="FILE_LOG_PATTERN">%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ}{UTC}}, %5p, %X{component:-SERVICE}, %X{event:-EVENT}, ${PID:-???}, [%t], %40.40logger{40}, FCID=%X{FCID:-N/A}, %msg%n</Property>
<Property name="MAX_HISTORY">7</Property>
<Property name="MAX_FILE_SIZE">100MB</Property>
</Properties>
<Appenders>
<RollingFile name="FILE"
fileName="${LOG_PATH}/tests.log"
filePattern="${LOG_PATH}/tests.%d{yyyy-MM-dd}.%i.log.gz">
<PatternLayout>
<Pattern>${FILE_LOG_PATTERN}</Pattern>
</PatternLayout>
<Policies>
<OnStartupTriggeringPolicy/>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="${MAX_FILE_SIZE}"/>
</Policies>
<DefaultRolloverStrategy max="${MAX_HISTORY}"/>
</RollingFile>
</Appenders>
<Loggers>
<logger name="org.springframework" level="INFO"/>
<logger name="org.springframework.security.oauth2" level="INFO"/>
<logger name="org.springframework.http" level="ERROR"/>
<Logger name="org.springframework.boot" level="info"/>
<Logger name="org.springframework.boot.context.embedded.jetty" level="info"/>
<Root level="error">
<AppenderRef ref="FILE"/>
</Root>
</Loggers>
when I start the application I get this error:
ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile. java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.RollingFileAppender
If I remove one of the policies this error not showing. What is the problem?

Log4j 2 console output stop working

I've been using log4j 2 (2.7) and it worked very well until I had to reinstall the IDE (Eclipse Neon J2EE edition).
Now I only works loggingto a log file but not to the console.
This is my log4j2.xml file:
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<File name="log" fileName="target/test.log" append="true">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M %msg%xEx%n"/>
</File>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
<Root level="TRACE">
<AppenderRef ref="log" />
</Root>
</Loggers>
The output to the log works perfectly, as I said.
Try declaring Root only once.
Example:
<Loggers>
<Root>
<AppenderRef ref="Console" level="error"/>
<AppenderRef ref="log" level="trace"/>
</Root>
</Loggers>
I agree with Sazzad 's answer: you can only have one root logger. I would suggest specifying a level on the root logger and override the level only on the AppenderRef that need it. So:
<Loggers>
<Root level="trace">
<AppenderRef ref="Console" level="error"/>
<AppenderRef ref="log"/>
</Root>
</Loggers>
Also, not sure if this was omitted just from the question or from the actual configuration file, but the configuration really should start with a <Configuration> and end with a </Configuration> element.

Resources