1
votes

I have come across an odd problem, which I do not understand:

when I remove my File appender it prevents me logging to my server, even though the File appender should not be responsible for logging anything to the server; that task should only be for my GELF appender.

The following code is able to log both to my console and server just fine

Java

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class App {
    private static final Logger log4j = LogManager.getLogger(App.class.getName());

    public static void main(String[] args) {
        log4j.info("This is my info message");
        log4j.warn("This is my warning message");
        log4j.error("This is my error message");
        log4j.fatal("This is my fatal message");
    }
}

XML

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

    <Properties>
        <Property name="default_pattern">%d{MM/dd/yyyy hh:mm:ss} %5p %c{1} - %m%n </Property>
    </Properties>
    <Appenders>
        <Console name="console">
            <PatternLayout pattern="${default_pattern}" />
            <Filters>
                <!-- Exclude messages logged above INFO -->
                <ThresholdFilter level="WARN" onMatch="DENY"
                    onMismatch="NEUTRAL" />
            </Filters>
        </Console>

        <File name="everything" fileName="everything.log"> <!--trying to remove this-->
            <PatternLayout pattern="${default_pattern}" />
        </File>

        <GELF name="gelfAppender" server="graylog.x.something.com"
            hostName="some.host" port="12201">
            <PatternLayout pattern="${default_pattern}" />
            <KeyValuePair key="extractStacktrace" value="true" />
            <KeyValuePair key="addExtendedInformation" value="true" />
            <KeyValuePair key="facility" value="gelf-java" />
            <KeyValuePair key="environment" value="Test" />
            <KeyValuePair key="application" value="MyApp" />
            <KeyValuePair key="additionalFields" value="{'environment': 'Test', 'application': 'MyAPP'}" />
        </GELF>

    </Appenders>
    <Loggers>
        <Root level="trace">
            <AppenderRef ref="console" level="info" />
            <AppenderRef ref="everything" /><!--and trying to remove this-->
            <AppenderRef ref="gelfAppender" level="info" />
        </Root>
    </Loggers>
</Configuration>

However, when I remove this

<File name="everything" fileName="everything.log">
    <PatternLayout pattern="${default_pattern}" />
</File>

and

<AppenderRef ref="everything" />

it no longer logs anything to my server.

Shouldn't the File appender and logger only log to a file and not the server? If so, why would removing the File logger and appender prevent me from logging to the server?

2
Is it possible your expectations are incorrect? The log level of gelfAppender is info while your everything appender accepts all levels.D.B.
Interesting. Does it make any difference if you remove the ThresholdFilter from the Console appender configuration?Remko Popma
What happens if you remove the level attribute on both AppenderRef elements and change level="trace" to level="info"?Raniz
@RemkoPopma No, the output is still the samemr nooby noob
@Raniz Well I only want to output levels of INFO or higher, so I wouldn't want to do that.mr nooby noob

2 Answers

1
votes

You may have found a bug. Please raise a ticket for this on the Log4j 2 issue tracker.