0

I have a log4j2.xml as follows:

<?xml version="1.0" encoding="UTF-8"?>
    <Configuration>
        <Properties>
            <Property name="dir" value="/var/log/sunverge" />
            <Property name="file" value="maggie.log" />
            <Property name="eatonemcbfile" value="eaton.log" />
        </Properties>

        <Appenders>
            <Console name="STDOUT" target="SYSTEM_OUT">
                <PatternLayout pattern="%d{ISO8601} %5p [%t] %c - %m%n" />
            </Console>
            <RollingFile name="file" fileName="${dir}/${file}"
                filePattern="${dir}/${file}.%d{yyyy-MM-dd}">
                <PatternLayout>
                    <Pattern>%d{ISO8601} %5p [%t] %c - %m%n</Pattern>
                </PatternLayout>
                <Policies>
                    <TimeBasedTriggeringPolicy interval="1" />
                </Policies>
            </RollingFile>
            <RollingFile name="eaton"
                fileName="${dir}/${eatonemcbfile}"
                filePattern="${dir}/${eatonemcbfile}.%d{yyyy-MM-dd}">
                <PatternLayout>
                    <Pattern name="ConversionPattern"> %d{ISO8601} %5p [%t] %c - %m%n</Pattern>
                </PatternLayout>
                <ThresholdFilter level="debug"/>
                <Policies>
                    <TimeBasedTriggeringPolicy interval="1" />
                </Policies>
            </RollingFile>
        </Appenders>

        <Loggers>
            <Root level="warn">
                <AppenderRef ref="file" />
            </Root>
            <logger name="com.sunverge.devices.eaton.emcb" level="info">
                <AppenderRef ref="eaton" />
                <AppenderRef ref="file" />
            </logger>
        </Loggers>
    </Configuration>

So however, I set the threshold for the eaton.log to be debug but both of them log the debug level. For some reason I don't want to add add the ThresholdFilter tag for the other file. Any help appreciated.

omid
  • 21
  • 4

1 Answers1

0

You should not be getting debug logs to any of your files as none of your loggers is configured to accept debug messages. If you are seeing them in the file then this configuration is not being used. You can verify whether it is being used or not by adding status="debug" to the configuration element and looking at what Log4j is configuring. If you don't see log4j debug output then that is a clear sign the configuration file is not being used. You can also add -Dlog4j2.debug=true to the command line which will cause the log4j logs to be output. You can inspect that to see where the configuration is coming from.

I would recommend changing your configuration to:

    <Appenders>
        <Console name="STDOUT" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{ISO8601} %5p [%t] %c - %m%n" />
        </Console>
        <RollingFile name="file" fileName="${dir}/${file}"
            filePattern="${dir}/${file}.%d{yyyy-MM-dd}">
            <PatternLayout>
                <Pattern>%d{ISO8601} %5p [%t] %c - %m%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" />
            </Policies>
        </RollingFile>
        <RollingFile name="eaton"
            fileName="${dir}/${eatonemcbfile}"
            filePattern="${dir}/${eatonemcbfile}.%d{yyyy-MM-dd}">
            <PatternLayout>
                <Pattern name="ConversionPattern"> %d{ISO8601} %5p [%t] %c - %m%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" />
            </Policies>
        </RollingFile>
    </Appenders>

    <Loggers>
        <Root level="warn">
            <AppenderRef ref="file" />
        </Root>
        <logger name="com.sunverge.devices.eaton.emcb" level="debug" additivity="false">
            <AppenderRef ref="eaton" level="debug"/>
            <AppenderRef ref="file" level="info"/>
        </logger>
    </Loggers>
</Configuration>
rgoers
  • 8,696
  • 1
  • 22
  • 24