RaceBase
RaceBase

Reputation: 18868

Log4j2 not creating log files

I am trying out log4j2 configuration

<?xml version="1.0" encoding="UTF-8"?>

<configuration status="info">
    <appenders>
        <Console name="console-log" target="SYSTEM_OUT" append="false">
            <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36}:%L %M - %msg%xEx%n"/>
        </Console>
        <File name="debug-log" fileName="${catalina.base}/logs/debug.log" append="false">
            <PatternLayout pattern="%d{yyyy-MM-dd 'at' HH:mm:ss.SSS z} %-5level %class{36}:%L %M - %msg%xEx%n"/>
        </File>
        <File name="trace-log" fileName="${catalina.base}/logs/trace.log" append="false">
            <PatternLayout pattern="%d{yyyy-MM-dd 'at' HH:mm:ss.SSS z} %-5level %class{36}:%L %M - %msg%xEx%n"/>
        </File>
        <File name="error-log" fileName="${catalina.base}/logs/error.log" append="false">
            <PatternLayout pattern="%d{yyyy-MM-dd 'at' HH:mm:ss.SSS z} %-5level %class{36}:%L %M - %msg%xEx%n"/>
        </File>
    </appenders>
    <loggers>
        <root level="debug" additivity="false">
            <appender-ref ref="console-log"/>
        </root>
        <Logger name="com.mypackage" level="debug" additivity="false">
            <appender-ref ref="debug-log" level="debug"/>
            <appender-ref ref="trace-log" level="info"/>
            <appender-ref ref="error-log" level="error"/>
        </Logger>
    </loggers>
</configuration>

I am getting logging and data to catalina.out but the rest of the files are not getting created. Couldn't figure out the silly mistake I might be doing here? and How do I create one more file which can have the appended logs of debug-log,trace-log,error-log only.

Upvotes: 0

Views: 6463

Answers (1)

rewolf
rewolf

Reputation: 5891

You have an error in your config:

Console appenders shouldn't have an append attribute. Removing that should fix your config.

Additionally the additivity attribute on the Root logger is unnecessary. It does nothing, as there is no higher logger to add to.

You should definitely have seen a line like the following in your output, warning you about the bad config:

ERROR Console contains an invalid element or attribute "append"

Upvotes: 1

Related Questions