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
Related
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.
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.
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?
How do I print just the INFO levels?
My current log is printing all INFO, WARN, ERROR and FATAL levels to console - I understand why this is happening. (because they are all above INFO)
Is there a way to just specify that just and only just, INFO levels get sent to the console appender and not everything above it?
Currently have the following log4j2 xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="App" packages="">
<Appenders>
<File name="logFile" fileName="C:\Users\user\workspace\logs\log.out">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</File>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="com.App" level="info" additivity="false">
<AppenderRef ref="logFile" level="error"/>
<AppenderRef ref="Console" level="info"/>
</Logger>
<Root level="error">
<AppenderRef ref="logFile" />
</Root>
</Loggers>
Need to use a ThresholdFilter;
<ThresholdFilter level="WARN" onMatch="DENY" onMismatch="ACCEPT" />
This blocks the WARN level and everything above it. So now it only accepts info.
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.