We are moving from log4j1.x to log4j2
Changed the properties file to xml file to support log4j2
Below is the xml file which we are using
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug">
<Appenders>
<RollingFile name="syslog" fileName="/var/log/stor/gui/gui.log" filePattern="/var/log/stor/gui/gui-%d{MM-dd-yyyy}-%i.log" append="true">
<PatternLayout>
<pattern>%d %p %m%n</pattern>
</PatternLayout>
<Filters>
<!-- Now deny warn, error and fatal messages -->
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL"/>
<!-- This filter accepts info, warn, error, fatal and denies debug/trace -->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="16 MB"/>
</Policies>
<DefaultRolloverStrategy max="1"/>
</RollingFile>
</Appenders>
<appenders>
<RollingFile name="requestUrilog" fileName="/var/log/stor/gui/requestUrilog.log" filePattern="/var/log/stor/gui/requestUrilog-%d{MM-dd-yyyy}-%i.log" append="true">
<PatternLayout>
<pattern>%d %p %m%n</pattern>
</PatternLayout>
<Filters>
<!-- Now deny warn, error and fatal messages -->
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL"/>
<!-- This filter accepts info, warn, error, fatal and denies debug/trace -->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="8 MB"/>
</Policies>
<DefaultRolloverStrategy max="4"/>
</RollingFile>
</appenders>
<appenders>
<RollingFile name="userlog" fileName="/var/log/stor/gui/userlog.log" filePattern="/var/log/stor/gui/userlog-%d{MM-dd-yyyy}-%i.log" append="true">
<PatternLayout>
<pattern>%d %p %m%n</pattern>
</PatternLayout>
<Filters>
<!-- Now deny warn, error and fatal messages -->
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="fatal" onMatch="DENY" onMismatch="NEUTRAL"/>
<!-- This filter accepts info, warn, error, fatal and denies debug/trace -->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="8 MB"/>
</Policies>
<DefaultRolloverStrategy max="4"/>
</RollingFile>
</appenders>
<Loggers>
<Logger name="com.tms.gui.sys" additivity="false" level="info">
<AppenderRef ref="syslog"/>
</Logger>
<Logger name="com.tms.gui.requestUri" additivity="false" level="info">
<AppenderRef ref="requestUrilog"/>
</Logger>
<Logger name="com.tms.gui.user" additivity="false" level="info">
<AppenderRef ref="userlog"/>
</Logger>
<Root level="info">
<AppenderRef ref="syslog"/>
</Root>
</Loggers>
</Configuration>
below is the debuf info which we are getting for the error
DEBUG Found factory method [createLoggers]: public static org.apache.logging.log4j.core.config.Loggers org.apache.logging.log4j.core.config.LoggersPlugin.createLoggers(org.apache.logging.log4j.core.config.LoggerConfig[]).
2016-01-14 12:40:14,757 localhost-startStop-1 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.LoggersPlugin for element Loggers with params(={com.tms.gui.sys, com.tms.gui.requestUri, com.tms.gui.user, root})
2016-01-14 12:40:14,758 localhost-startStop-1 DEBUG Built Plugin[name=loggers] OK from factory method.
2016-01-14 12:40:14,758 localhost-startStop-1 ERROR Unable to locate appender requestUrilog for logger com.tms.gui.requestUri
2016-01-14 12:40:14,758 localhost-startStop-1 ERROR Unable to locate appender syslog for logger
2016-01-14 12:40:14,758 localhost-startStop-1 ERROR Unable to locate appender syslog for logger com.tms`enter code here`.gui.sys
2016-01-14 12:40:14,759 localhost-startStop-1 DEBUG Configuration XmlConfiguration[location=/opt/stor/gui/www/WEB-INF/classes/log4j2.xml] initialized
please guide us on what we are doing wrong
The ThresholdFilter checks for the level of the log event being the same or more specific than the specified level. So the filter that checks for level "warn" and on a match does a DENY will also deny error and fatal as well, making the next two filters unnecessary.
Can you provide the debug info for creating the appenders? It is possible that the appenders can't be found because problems were encountered creating them, possibly because of permissions problems creating a file in the /var/log directory.
Related
I have a very simple requirement to write DEBUG logs to a file but shouldn't keep that file for more than an hour due to audit purposes. So, is there a way to overwrite the same file (file_debug) every hour automatically?
I've seen there is "delete" in log4j2 as below but don't want to use this due to security issues. Also, append="false" won't work for me as I need to retain events for an hour - not overwrite every event immediately.
<DefaultRolloverStrategy>
<Delete basePath="${baseDir}" maxDepth="2">
<IfFileName glob="*/app-*.log.gz" />
<IfLastModified age="P60D" />
</Delete>
</DefaultRolloverStrategy>
My current log4j2.xml
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<Appenders>
<RollingFile name="file" fileName="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}log4j_poc.log" filePattern="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}log4j_poc_%i.log">
<PatternLayout pattern="%-5p %d [%t] [processor: %X{processorPath}; event: %X{correlationId}] %c: %m%n"/>
<SizeBasedTriggeringPolicy size="10 MB"/>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
<RollingFile name="file_debug" fileName="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}log4j_poc_debug.log" filePattern="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}log4j_poc_debug.log">
<Filters>
<ThresholdFilter level="TRACE"/>
<ThresholdFilter level="INFO" onMatch="DENY" onMismatch="NEUTRAL"/>
</Filters>
<PatternLayout pattern="%-5p %d [%t] [processor: %X{processorPath}; event: %X{correlationId}] %c: %m%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="10 MB"/>
<CronTriggeringPolicy schedule="0 0 * * * ?"/>
</Policies>
<DefaultRolloverStrategy max="0"/>
</RollingFile>
</Appenders>
<Loggers>
<!-- Http Logger shows wire traffic on DEBUG. -->
<AsyncLogger name="org.mule.service.http.impl.service.HttpMessageLogger" level="DEBUG" />
<AsyncLogger name="org.mule.service.http" level="WARN"/>
<AsyncLogger name="org.mule.extension.http" level="WARN"/>
<AsyncLogger name="org.mule.extension.db" level="DEBUG"/>
<AsyncLogger name="org.mule.db.commons" level="DEBUG"/>
<!-- Mule logger -->
<AsyncLogger name="org.mule.runtime.core.internal.processor.LoggerMessageProcessor" level="INFO"/>
<AsyncRoot level="INFO">
<AppenderRef ref="file" level="INFO"/>
<AppenderRef ref="file_debug" level="TRACE"/>
</AsyncRoot>
</Loggers>
Please suggest if there is any option to overwrite the same file "file_debug" every hour?
log4j2 version : 2.7
My project is a high concurrent system, I use log4j2 asyncAppender to save logs, but every nigh at 00:00:00 when the rollover strategy triggering, the event blocked at rollover process.
the appender create lots of threads and occured a memory leak, here is my config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="info">
<Properties>
<Property name="logDir">/data/logs/q-mix</Property>
<Property name="rollingSuffix">log.gz</Property>
<Property name="CONSOLE_LOG_PATTERN">%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{%5.5T}{magenta} %clr{---}{faint} %clr{[%20.20t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n</Property>
<Property name="FILE_LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} %5p %5.5T --- [%20.20t] %-40.40c{1.} : %m%n</Property>
</Properties>
<appenders>
<console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="${CONSOLE_LOG_PATTERN}" />
</console>
<RollingFile name="RollingFileInfo" fileName="${logDir}/info.log"
filePattern="${logDir}/logs/%d{yyyy-MM-dd}-%i-info.${rollingSuffix}">
<Filters>
<ThresholdFilter level="INFO"/>
</Filters>
<PatternLayout pattern="${FILE_LOG_PATTERN}"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="2048 MB"/>
</Policies>
<DefaultRolloverStrategy max="80">
<Delete basePath="${logDir}/logs/" maxDepth="1">
<IfFileName glob="*.${rollingSuffix}">
<IfAny>
<IfAccumulatedFileSize exceeds="50 GB" />
<IfLastModified age="15d" />
</IfAny>
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
<RollingFile name="RollingFileWarn" fileName="${logDir}/warn.log"
filePattern="${logDir}/logs/%d{yyyy-MM-dd}-%i-warn.${rollingSuffix}">
<Filters>
<ThresholdFilter level="WARN"/>
</Filters>
<PatternLayout pattern="${FILE_LOG_PATTERN}"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
<DefaultRolloverStrategy max="40"/>
</RollingFile>
<RollingFile name="RollingFileError" fileName="${logDir}/error.log"
filePattern="${logDir}/logs/%d{yyyy-MM-dd}-%i-error.${rollingSuffix}">
<ThresholdFilter level="ERROR"/>
<PatternLayout pattern="${FILE_LOG_PATTERN}"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
<DefaultRolloverStrategy max="40"/>
</RollingFile>
<RollingFile name="RollingFileAlarm" fileName="${logDir}/alarm.log"
filePattern="${logDir}/logs/%d{yyyy-MM-dd}-%i-alarm.${rollingSuffix}">
<PatternLayout pattern="${FILE_LOG_PATTERN}"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
<DefaultRolloverStrategy max="40"/>
</RollingFile>
<Async name="async" bufferSize="1024000">
<!-- <appender-ref ref="Console"/>-->
<appender-ref ref="RollingFileInfo"/>
<!-- <appender-ref ref="RollingFileWarn"/>-->
<appender-ref ref="RollingFileError"/>
</Async>
</appenders>
<loggers>
<logger name="com.upex.exchange.robot.util.AlarmUtils" level="error">
<appender-ref ref="RollingFileAlarm"/>
</logger>
<root level="info">
<appender-ref ref="async"/>
</root>
</loggers>
</configuration>
Here is the stacktrace:
AsyncAppender-async
at sun.misc.Unsafe.park(ZJ)V (Native Method)
at java.util.concurrent.locks.LockSupport.park(Ljava/lang/Object;)V (LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt()Z (AbstractQueuedSynchronizer.java:836)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(I)V (AbstractQueuedSynchronizer.java:997)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(I)V (AbstractQueuedSynchronizer.java:1304)
at java.util.concurrent.Semaphore.acquire()V (Semaphore.java:312)
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.rollover(Lorg/apache/logging/log4j/core/appender/rolling/RolloverStrategy;)Z (RollingFileManager.java:247)
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.rollover()V (RollingFileManager.java:192)
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.checkRollover(Lorg/apache/logging/log4j/core/LogEvent;)V (RollingFileManager.java:175)
at org.apache.logging.log4j.core.appender.RollingFileAppender.append(Lorg/apache/logging/log4j/core/LogEvent;)V (RollingFileAppender.java:280)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(Lorg/apache/logging/log4j/core/LogEvent;)V (AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(Lorg/apache/logging/log4j/core/LogEvent;)V (AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(Lorg/apache/logging/log4j/core/LogEvent;)V (AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(Lorg/apache/logging/log4j/core/LogEvent;)V (AppenderControl.java:84)
at org.apache.logging.log4j.core.appender.AsyncAppender$AsyncThread.callAppenders(Lorg/apache/logging/log4j/core/LogEvent;)Z (AsyncAppender.java:451)
at org.apache.logging.log4j.core.appender.AsyncAppender$AsyncThread.run()V (AsyncAppender.java:404)
This is the Eclipse Memory Analyzer leak report:
One instance of "java.util.concurrent.ArrayBlockingQueue" loaded by "<system class loader>" occupies 897,341,688 (95.23%) bytes.
The instance is referenced by org.apache.logging.log4j.core.appender.AsyncAppender$AsyncThread # 0xc0700150 AsyncAppender-async ,
loaded by "org.springframework.boot.loader.LaunchedURLClassLoader # 0xc0400000".
The memory is accumulated in one instance of "java.lang.Object[]" loaded by "<system class loader>".
The stacktrace of this Thread is available. See stacktrace.
Keywords
java.util.concurrent.ArrayBlockingQueue
java.lang.Object[]
org.springframework.boot.loader.LaunchedURLClassLoader # 0xc0400000
How can i change some configs to resolve this problem, I realy need some help. Thanks a lot.
Sorry for my english grammar
According to log4j's sugguest I upgrade the log4j2 to version 2.14
LMAX Disruptor technology. Asynchronous Loggers internally use the Disruptor, a lock-free inter-thread communication library, instead of queues, resulting in higher throughput and lower latency.
the new config xml like this:
<appenders>
<RollingRandomAccessFile name="RollingFileWarn" fileName="${logDir}/warn.log"
filePattern="${logDir}/logs/%d{yyyy-MM-dd}-%i-warn.${rollingSuffix}" immediateFlush="false">
<Filters>
<ThresholdFilter level="WARN"/>
</Filters>
<PatternLayout pattern="${FILE_LOG_PATTERN}"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="1024 MB"/>
</Policies>
<DefaultRolloverStrategy max="40"/>
</RollingRandomAccessFile>
</appenders>
<loggers>
<logger name="com.upex.exchange.robot.util.AlarmUtils" level="error">
<appender-ref ref="RollingFileAlarm"/>
</logger>
<AsyncRoot level="info" includeLocation="true">
<appender-ref ref="RollingFileInfo"/>
<appender-ref ref="RollingFileError"/>
</AsyncRoot>
</loggers>
Add a log4j2.component.properties to classpath,content config:
log4j2.AsyncQueueFullPolicy=Discard
AsyncLoggerConfig.SynchronizeEnqueueWhenQueueFull=true
AsyncLoggerConfig.RingBufferSize=131072
This new way may solve the memory leak problem(not confirmed), Because when the TimeBasedTriggeringPolicy started, the cpu load increased five times than usual , it seams still blocked when policy is triggering. However, this configuration limits the queue length and queue full policy. I will continue to observe
I am trying to configure log4j2 to write logs in several files using Routing & RollingFile appenders, and so far everything works well. However, there is an unwanted side effect - it also logs into Linux syslog. Is there any way to disable logging into syslog? Here is my log4j2.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration name="Staging" status="warn">
<Properties>
<Property name="pattern" value="%-5level [%d{DEFAULT}] %logger{30} %X %marker %msg%n"/>
<Property name="log-path" value="/var/log/application"/>
<Property name="file-size" value="200 MB"/>
<Property name="file-total" value="10"/>
</Properties>
<Appenders>
<RollingFile name="SESSIONS_APPENDER" fileName="${log-path}/sessions.log" filePattern="${log-path}/sessions-%i.log.gz" append="true">
<PatternLayout pattern="${pattern}"/>
<Policies>
<SizeBasedTriggeringPolicy size="${file-size}"/>
</Policies>
<DefaultRolloverStrategy max="${file-total}"/>
</RollingFile>
<RollingFile name="TRANSACTIONS_APPENDER" fileName="${log-path}/transactions.log" filePattern="${log-path}/transactions-%i.log.gz" append="true">
<PatternLayout pattern="${pattern}"/>
<Policies>
<SizeBasedTriggeringPolicy size="${file-size}"/>
</Policies>
<DefaultRolloverStrategy max="${file-total}"/>
</RollingFile>
<RollingFile name="STDROUT_APPENDER" fileName="${log-path}/stdrout.log" filePattern="${log-path}/stdrout-%i.log.gz" append="true">
<PatternLayout pattern="${pattern}"/>
<Policies>
<SizeBasedTriggeringPolicy size="${file-size}"/>
</Policies>
<DefaultRolloverStrategy max="${file-total}"/>
<!-- Filtering from the stdout log, lines that have their own custom appender -->
<Filters>
<MarkerFilter marker="TRANSACTION" onMatch="DENY" onMismatch="NEUTRAL"/>
<MarkerFilter marker="SESSION" onMatch="DENY" onMismatch="NEUTRAL"/>
</Filters>
</RollingFile>
<Routing>
<name>ROUTING_APPENDER</name>
<Routes>
<pattern>$${marker:}</pattern>
<!-- Default appender if no matching marker found -->
<Route ref="STDROUT_APPENDER"/>
<!-- Appender selection for specific marker -->
<Route key="TRANSACTION" ref="TRANSACTIONS_APPENDER"/>
<Route key="SESSION" ref="SESSIONS_APPENDER"/>
</Routes>
</Routing>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="STDROUT_APPENDER"/>
</Root>
<Logger name="com.application" level="info" additivity="false">
<AppenderRef ref="ROUTING_APPENDER"/>
</Logger>
<Logger name="org.apache" level="error">
<AppenderRef ref="STDROUT_APPENDER"/>
</Logger>
<Logger name="com.amazonaws" level="error">
<AppenderRef ref="STDROUT_APPENDER"/>
</Logger>
</Loggers>
</Configuration>
Application is still point to log4j 1.2 after upgrading to log4j 2.5. find below log4j2.xml file and warnings which i got on server start up.
Based on below configurations it supposed to create log files but it is not creating.
Note:blow configurations are working in local system but not working when I am deploying in server.
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="TRACE">
<Properties>
<Property name="rotateLogsInterval">6</Property>
<Property name="log.dir">D:\\Mconnect\\LOGGER</Property>
<Property name="log.INVALIDMNO.dir">D:\\Mconnect\\LOGGER\\INVALIDMNO</Property>
<Property name="log.MOBINL1000.dir">D:\\Mconnect\\LOGGER\\MOBINL1000</Property>
<Property name="log.ECONET1000.dir">D:\\Mconnect\\LOGGER\\ECONET1000</Property>
<Property name="log.AIRTEL1000.dir">D:\\Mconnect\\LOGGER\\AIRTEL1000</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%-5p %d [%t] %c: %m%n" />
</Console>
<File name="EIGInformation"
fileName="C:\\EIG_SOURCE_CODE\\EIG_20140901\\logs\\EIGInformation1.log">
<PatternLayout>
<Pattern>%5p | %m%n</Pattern>
</PatternLayout>
</File>
<!-- Debug logger -->
<RollingRandomAccessFile name="debugLogger"
fileName="${log.dir}/mconnectDebugLogger.log"
filePattern="${log.dir}/$${date:yyyy-MM}/mconnectDebugLogger-%d{yyyy-MM-dd-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%5p | %d | %m%n</Pattern>
</PatternLayout>
<!-- <DefaultRolloverStrategy> <Delete basePath="${log.dir}" maxDepth="2">
<IfFileName glob="*/mconnectDebugLogger-*.log.gz" /> <IfLastModified age="60d"
/> </Delete> </DefaultRolloverStrategy> -->
<Policies>
<TimeBasedTriggeringPolicy interval="${rotateLogsInterval}" />
</Policies>
</RollingRandomAccessFile>
<!-- Transaction tdr file -->
<RollingRandomAccessFile name="transactionDetails"
fileName="${log.dir}/TDR.log"
filePattern="${log.dir}/$${date:yyyy-MM}/TDR-%d{yyyy-MM-dd-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%5p | %d | %t:: | %m%n</Pattern>
</PatternLayout>
<!-- <DefaultRolloverStrategy> <Delete basePath="${log.dir}" maxDepth="2">
<IfFileName glob="*/TDR-*.log.gz" /> <IfLastModified age="60d" /> </Delete>
</DefaultRolloverStrategy> -->
<Policies>
<TimeBasedTriggeringPolicy interval="${rotateLogsInterval}" />
</Policies>
</RollingRandomAccessFile>
<!-- Connect Info General log. -->
<RollingRandomAccessFile name="connectInfoLogGeneral"
fileName="${log.INVALIDMNO.dir}/connectInfoLogGeneral.log"
filePattern="${log.INVALIDMNO.dir}/$${date:yyyy-MM}/connectInfoLogGeneral-%d{yyyy-MM-dd-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%5p | %d | %m%n</Pattern>
</PatternLayout>
<!-- <DefaultRolloverStrategy> <Delete basePath="${log.INVALIDMNO.dir}"
maxDepth="2"> <IfFileName glob="*/connectInfoLogGeneral-*.log.gz" /> <IfLastModified
age="60d" /> </Delete> </DefaultRolloverStrategy> -->
<Policies>
<TimeBasedTriggeringPolicy interval="${rotateLogsInterval}" />
</Policies>
</RollingRandomAccessFile>
<!-- Connect Process log. -->
<RollingRandomAccessFile name="connectProcessLogGeneral"
fileName="${log.INVALIDMNO.dir}/connectProcessLogGeneral.log"
filePattern="${log.INVALIDMNO.dir}/$${date:yyyy-MM}/connectProcessLogGeneral-%d{yyyy-MM-dd-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%5p | %d | %m%n</Pattern>
</PatternLayout>
<!-- <DefaultRolloverStrategy> <Delete basePath="${log.log.INVALIDMNO.dir.dir}"
maxDepth="2"> <IfFileName glob="*/connectProcessLogGeneral-*.log.gz" /> <IfLastModified
age="60d" /> </Delete> </DefaultRolloverStrategy> -->
<Policies>
<TimeBasedTriggeringPolicy interval="${rotateLogsInterval}" />
</Policies>
</RollingRandomAccessFile>
<!-- Connect Info log -->
<RollingRandomAccessFile name="connectInfoLogMOBINL1000"
fileName="${log.MOBINL1000.dir}/connectInfoMOBINL1000.log"
filePattern="${log.MOBINL1000.dir}/$${date:yyyy-MM}/connectInfoMOBINL1000-%d{yyyy-MM-dd-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%5p | %d | %m%n</Pattern>
</PatternLayout>
<!-- <DefaultRolloverStrategy> <Delete basePath="${log.MOBINL1000.dir}"
maxDepth="2"> <IfFileName glob="*/connectInfoMOBINL1000-*.log.gz" /> <IfLastModified
age="60d" /> </Delete> </DefaultRolloverStrategy> -->
<Policies>
<TimeBasedTriggeringPolicy interval="${rotateLogsInterval}" />
</Policies>
</RollingRandomAccessFile>
<!-- Connect Process log -->
<RollingRandomAccessFile name="connectProcessLogMOBINL1000"
fileName="${log.MOBINL1000.dir}/connectProcessMOBINL1000.log"
filePattern="${log.MOBINL1000.dir}/$${date:yyyy-MM}/connectProcessMOBINL1000-%d{yyyy-MM-dd-HH}-%i.log.gz">
<PatternLayout>
<Pattern>%5p | %d | %m%n</Pattern>
</PatternLayout>
<!-- <DefaultRolloverStrategy> <Delete basePath="${log.MOBINL1000.dir}"
maxDepth="2"> <IfFileName glob="*/connectProcessMOBINL1000-*.log.gz" /> <IfLastModified
age="60d" /> </Delete> </DefaultRolloverStrategy> -->
<Policies>
<TimeBasedTriggeringPolicy interval="${rotateLogsInterval}" />
</Policies>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<!-- CXF is used heavily by Mule for web services -->
<AsyncLogger name="org.apache.cxf" level="WARN" />
<!-- Apache Commons tend to make a lot of noise which can clutter the log -->
<AsyncLogger name="org.apache" level="INFO" />
<!-- Reduce startup noise -->
<AsyncLogger name="org.springframework.beans.factory"
level="WARN" />
<!-- Mule classes -->
<AsyncLogger name="org.mule" level="INFO" />
<AsyncLogger name="com.mulesoft" level="INFO" />
<AsyncLogger name="EIGInformation" level="INFO">
<AppenderRef ref="EIGInformation" />
</AsyncLogger>
<AsyncLogger
name="com.comviva.mconnect.webservices.impl.MConnectWebServices"
level="info">
<AppenderRef ref="debugLogger" />
</AsyncLogger>
<AsyncLogger name="transactionDetails" level="OFF">
<AppenderRef ref="debugLogger" />
</AsyncLogger>
<AsyncLogger name="connectInfoLogGeneral" level="INFO">
<AppenderRef ref="connectInfoLogGeneral" />
</AsyncLogger>
<AsyncLogger name="connectProcessLogGeneral" level="INFO">
<AppenderRef ref="connectProcessLogGeneral" />
</AsyncLogger>
<AsyncLogger name="connectInfoLogMOBINL1000" level="INFO">
<AppenderRef ref="connectInfoLogMOBINL1000" />
</AsyncLogger>
<AsyncLogger name="connectProcessLogMOBINL1000" level="INFO">
<AppenderRef ref="connectProcessLogMOBINL1000" />
</AsyncLogger>
<AsyncRoot level="INFO">
<AppenderRef ref="EIGInformation" />
</AsyncRoot>
</Loggers>
</Configuration>
log4j: Using URL [file:/home/contest/prd/muleTomcat/webapps/Connect-1.3.0/WEB-INF/classes/log4j2.xml] for automatic log4j configuration.
log4j: Preferred configurator class: org.apache.log4j.xml.DOMConfigurator
log4j: System property is :null
log4j: Standard DocumentBuilderFactory search succeded.
log4j: DocumentBuilderFactory is: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
log4j:WARN Continuable parsing error 2 and column 31
log4j:WARN Document root element "Configuration", must match DOCTYPE root "null".
log4j:WARN Document root element "Configuration", must match DOCTYPE root "null".
log4j:WARN Continuable parsing error 2 and column 31
log4j:WARN Document is invalid: no grammar found.log4j:WARN Document is invalid: no grammar found.
log4j:ERROR DOM element is - not a <log4j:configuration> element.
log4j:WARN No appenders could be found for logger (com.mchange.v2.log.MLog).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[localhost-startStop-1] INFO org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence
The problem is that the old log4j-1.2.x.jar is still in the classpath. Please remove it from the classpath and ensure the following jars are on the classpath:
log4j-api-2.x.jar
log4j-core-2.x.jar
log4j-1.2-api-2.x.jar - this adapter will route logging calls your application makes to the Log4j2 implementation.
I recommend using the most recent Log4j version for 2.x (2.7 as of this writing).
If you're using slf4j, please remove org.slf4j:slf4j-log4j12 (this is for the old Log4j 1) and add org.apache.logging.log4j:slf4j-impl.
I'm working with log4j2 and rolling appender file.
I want to use a customize layout but it's not working properly.
I'm working with JBoss. I have put the lib with the cusotmize layout in the libs directory, so it's in the class path.
In the log4j2.xml, I have put the following configuration:
<Configuration status="trace" packages="mypackage.audit">
...
<Routing name="RoutingAppender">
<Routes pattern="$${ctx:FlowName">
<Route>
<RollingFile name="Rolling-${ctx:FlowName}" fileName="logs/Audit-${ctx:FlowName}.log"
filePattern="./logs/Audit-${ctx:FlowName}-%d{yyyy-MM-dd}-%i.log.gz" >
<PatternLayout>
<pattern>%d{ISO8601} [%t] %p %c{3} - %m%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true" />
</Policies>
<Layout type="AuditLayout" locationInfo="true"/>
</RollingFile>
</Route>
</Routes>
</Routing>
</Appenders>
<Loggers>
<Logger name="CustomizeAuditing" level="info" >
<AppenderRef ref="RoutingAppender"/>
</Logger>
</Loggers>
</Configuration>
But nothing is logged correctly!
Thanks in advance
Jamila
following worked for me:
log4j2 version 2.2
and
<?xml version="1.0" encoding="UTF-8"?>
<Configuration packages="com.redknee.bssauto.helpers">
<Appenders>
<RollingFile name="Rolling-default" fileName="logs/bssauto.html"
filePattern="logs/$${date:yyyy-MM}/bssauto-%d{MM-dd-yyyy}-%i.log.gz">
<CustomHTMLLayout charset="UTF-8" title="BSSAuto Logs" locationInfo="true" />
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="Rolling-default"/>
</Root>
</Loggers>
</Configuration>
Notice following
<Configuration packages="com.redknee.bssauto.helpers">
here packages should have all packages containing custom class for layouts
<CustomHTMLLayout charset="UTF-8" title="BSSAuto Logs" locationInfo="true" />
and CustomHTMLLayout is custom class created by extending AbstractStringLayout