I am getting a lot of DEBUG messages in my logs. I want to suppress these, while preserving the INFO and ERROR messages. Here is my log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<!-- Author: Crunchify.com -->
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%t] %5p %c - %m%n" />
</Console>
<RollingFile name="RollingFile" filename="test.log"
filepattern="${LOG_PATH}${LOG_NAME}Log.%d{yyyyMMdd}.log.gz">
<PatternLayout pattern="%d [%t] %5p %c - %m%n" />
<Policies>
<SizeBasedTriggeringPolicy size="100 MB" />
</Policies>
<DefaultRolloverStrategy max="20" />
</RollingFile>
<NoSql name="elasticAppender">
<Elasticsearch cluster="test" host="test" port="test" index="test" type="log4j2"/>
</NoSql>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="NoSql" />
<AppenderRef ref="RollingFile" />
</Root>
<Logger name="test" level="info" additivity="false">
<AppenderRef ref="RollingFile" />
</Logger>
<Logger name="test" level="info">
</Logger>
<Logger name="test" level="INFO">
</Logger>
<Logger name="com.datastax.driver.core" level="INFO">
</Logger>
</Loggers>
</Configuration>
Does anyone know what change needs to be made here?
According to the Log4j manual, you might want to change <Root level="debug"> to <Root level="info">.
Related
I have log4j2.xml properties:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{bright,yellow}: %msg%n%throwable" />
</Console>
<RollingFile name="RollingFile"
fileName="/opt/tomcat/mylogs/logs.log"
filePattern="/opt/tomcat/mylogs/$${date:yyyy-MM}/log-%d{-dd-MMMM-yyyy}-%i.log.gz">
<PatternLayout>
<pattern>%d %p %C{1.} [%t] %m%n</pattern>
</PatternLayout>
<Policies>
<!-- rollover on startup, daily and when the file reaches 50 MegaBytes -->
<OnStartupTriggeringPolicy />
<SizeBasedTriggeringPolicy
size="50 MB" />
<TimeBasedTriggeringPolicy />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<!-- LOG everything at INFO level -->
<Root level="info">
<AppenderRef ref="Console" level="info" />
<AppenderRef ref="RollingFile" level="info" />
<AppenderRef ref="SmtpAppender" level="exception"/>
</Root>
<Logger name="com.kot" level="debug">
<AppenderRef ref="RollingFile"/>
</Logger>
</Loggers>
</Configuration>
But this properteis create logg files on another folder on server: "/opt/tomcat/mylogs/logs.log"
I want to split catalina.out logs. This logs are located on "/opt/tomcat/logs/catalina.out" by default
Also, how to split server logs and application logs?
I am using log4j in my project. The project is working fine but it is not creating a log file.
Here is the log4j.xml
<Configuration status="warn">
<Properties>
<Property name="logHome">D:/logs</Property>
</Properties>
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%-5p: %c - %m%n" />
</Console>
<RollingFile name="rollingFile" immediateFlush="true" fileName="${logHome}/mySample.log" filePattern="${logHome}/mySample-%i.log">
<PatternLayout>
<Pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} |[%t]| %-5p | %c{1} | %L - %m%n</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="5 MB" />
</Policies>
<DefaultRolloverStrategy max="10" />
</RollingFile>
</Appenders>
<Loggers>
<Logger name="org.springframework" level="info" includeLocation="true" />
<Logger name="org.hibernate" level="info" includeLocation="true" />
<Logger name="org.project" level="debug" includeLocation="true" />
<Root level="info" includeLocation="true">
<AppenderRef ref="rollingFile" />
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>
Any help is appreciated. Thanks in advance.
I tried all the ways out but nothing worked for me. At the end I had to switch to slf4j.Logger and slf4j.LoggerFactory. With the help of this I was able to generate logs.
Example:
private static final Logger LOGGER=LoggerFactory.getLogger(MyClass.class);
I have this xml config file for log4j2 but the loggers don't work. If I set the referince for root logger as "Errors" of "Info" (my new appenders) when I run the program the logger works and writes the data to logger files but if I set thouse appenders to my new loggers ("Information" and "ErrorLog") the logger doesn't write any data to my log files.
Here is my configuration xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<File name="Info" fileName="logs/info.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</File>
<File name="Errors" fileName="logs/errors.log">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
</File>
</Appenders>
<Loggers>
<Logger name="Information" level="debug">
<AppenderRef ref="Info"/>
</Logger>
<Logger name="ErrorLog" level="error">
<AppenderRef ref="Errors"/>
</Logger>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
Solved!
I modified the Loggers section and I deleted those 2 Loggers.
<Loggers>
<Root level="debug">
<level value="DEBUG" />
<appender-ref ref="Console" />
<appender-ref ref="Info" />
<appender-ref ref="Errors" />
</Root>
</Loggers>
I'm using log4j2 for logging in my app. Basically it's logging uncatched exceptions (Error.log) and logging changes of my data at service layer (journal.log; journalJSON.log).
And here's the thing, when I'm starting service layer tests every log appears in the file and console, but when I'm using application deployed in tomcat they're only in console. What's happening?
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="WARN">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<File name="Error" fileName="logs/error.log"
immediateFlush="true" append="true">
<PatternLayout pattern=" \n\n %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
<RandomAccessFile name="Journal" fileName="logs/journal.log" immediateFlush="true" append="true">
<PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss.SSS}] %msg%n"/>
</RandomAccessFile>
<File name="JournalJSON" fileName="logs/journalJSON.log" immediateFlush="true" append="false">
<JSONLayout complete="true" charset="UTF-8" compact="false" eventEol="false"/>
</File>
</appenders>
<Loggers>
<Logger name="com.user.controller" level="error" additivity="false">
<AppenderRef ref="Error" level="error"/>
<AppenderRef ref="Console" level="error"/>
</Logger>
<Logger name="com.user.service" level="info" additivity="false">
<appender-ref ref="JournalJSON" level="info"/>
<appender-ref ref="Journal" level="info"/>
<appender-ref ref="Console" level="info"/>
</Logger>
<Root level="warn">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
Well, there are a couple of possibilities I can think of:
Your configuration file isn't being found and it is using the default configuration.
The logger for your application isn't com.user.controller or com.user.service and the root logger is being used.
I'd like to log all incoming and outgoing CXF requests to a specific logfile. But all I get with the following configuration is a console output. What is wrong here?
log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>
<RollingFile name="CXF" fileName="cxf.log">
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
</RollingFile>
</Appenders>
<Loggers>
<logger name="org.apache.cxf" additivity="false" level="info">
<AppenderRef ref="CXF"/>
</logger>
<logger name="org.apache.cxf.interceptor.LoggingInInterceptor" additivity="false" level="info">
<AppenderRef ref="CXF" />
</logger>
<logger name="org.apache.cxf.interceptor.LoggingOutInterceptor" additivity="false" level="info">
<AppenderRef ref="CXF" />
</logger>
<Root level="all">
<AppenderRef ref="CONSOLE" />
</Root>
</Loggers>
</Configuration>
src/main/resources/META-INF/cxf/org.apache.cxf.Logger:
org.apache.cxf.common.logging.Log4jLogger
As a workaround, I'm now using org.apache.cxf.common.logging.Slf4jLogger and the bridge dependency.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.0</version>
</dependency>
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Properties>
<property name="main">logs/main.log</property>
<property name="webservice">logs/webservice.log</property>
<property name="sql">logs/sql.log</property>
<property name="mongoexceptions">logs/mongoexceptions.log</property>
</Properties>
<Appenders>
<RollingFile name="mongoexceptions-all" fileName="${mongoexceptions}"
filePattern="${mongoexceptions}.%i" bufferedIO="false" bufferSize="8192">
<PatternLayout>
<pattern>%d{dd MMM HH:mm:ss:SSS} %p [%t] - %m ---- %c%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10000KB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="main-all" fileName="${main}"
filePattern="${main}.%i" bufferedIO="false" bufferSize="8192">
<PatternLayout>
<pattern>%d{dd MMM HH:mm:ss:SSS} %p [%t] - %m ---- %c%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10000KB" />
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingFile>
<RollingFile name="webservice-all" fileName="${webservice}" filePattern="${webservice}.%i" bufferedIO="false" bufferSize="8192">
<PatternLayout>
<pattern>%d{dd MMM HH:mm:ss:SSS} %p [%t] - %m %n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10000KB" />
</Policies>
<DefaultRolloverStrategy max="5"/>
</RollingFile>
<RollingFile name="sql-all" fileName="${sql}" filePattern="${sql}.%i" bufferedIO="true" bufferSize="8192">
<PatternLayout pattern="%d [%t] %-5p %c - %m%n" />
<Policies>
<SizeBasedTriggeringPolicy size="1000KB" />
</Policies>
<DefaultRolloverStrategy max="1"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="info" additivity="false">
<AppenderRef ref="main-all"/>
</Root>
<Logger name="org.apache.cxf" additivity="false" level="warn">
<appender-ref ref="main-all"/>
</Logger>
<Logger name="org.springframework" additivity="false" level="warn">
<appender-ref ref="main-all"/>
</Logger>
<Logger name="org.eclipse.jetty" additivity="false" level="warn">
<appender-ref ref="main-all"/>
</Logger>
<Logger name="com.main.bam.db.edp.EventAuditDAO" level="error" additivity="false">
<appender-ref ref="mongoexceptions-all" />
</Logger>
<Logger name="com.main.bam.db.edp.ExceptionsLogDAO" level="error" additivity="false">
<appender-ref ref="mongoexceptions-all" />
</Logger>
<Logger name="com.main.bam.db.edp.ClaimDAO" level="debug">
<appender-ref ref="webservice-all" />
</Logger>
<Logger name="com.main.bam.db.edp.CPDSummaryDAO" level="debug">
<appender-ref ref="webservice-all" />
</Logger>
<Logger name="DBConnectionFactory" level="info">
<appender-ref ref="sql-all"/>
</Logger>
</Loggers>
</Configuration>
Here is the working example.