Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log4j.properties ignored #11

Open
chaya93 opened this issue Nov 8, 2017 · 2 comments
Open

log4j.properties ignored #11

chaya93 opened this issue Nov 8, 2017 · 2 comments

Comments

@chaya93
Copy link

chaya93 commented Nov 8, 2017

Hi :)

I wanted to add a custom log4.properties file with content:

log4j.rootLogger=TRACE, STDOUT

# CONSOLE appender not used by default
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%m

yet this setting is being ignored :(
The output I receive is
09:52:32.723 [main] INFO com.blabla.Test - {"message":"It works!","test":"blaaaa","level":"INFO","thread_name":"main","class":"com.blabla.Test","@timestamp":"2017-11-08 09:52:32.713+0100"}

yet I want it to be
{"message":"It works!","test":"blaaaa","level":"INFO","thread_name":"main","class":"com.blabla.Test","@timestamp":"2017-11-08 09:52:32.713+0100"}

I use it in my code like this:

import com.savoirtech.logging.slf4j.json.LoggerFactory;
import com.savoirtech.logging.slf4j.json.logger.Logger;

public class Test {


    public static void main(String[] args) {
        LoggerFactory.setIncludeLoggerName(false);

        Logger logger = LoggerFactory.getLogger(Test.class);

        logger.info().message("It works!").field("test", "blaaaa").log();
    }
}

Any help would really be appreciated :)

Regards
Anna

@artnaseef
Copy link
Member

This looks to be an issue at the log4j level. I can help track down the problem if provided a (preferably minimal) project that demonstrates the problem.

Note that I took the example Test code provided and put it into my own test project and it worked as desired.

@artnaseef
Copy link
Member

Here's the sample project I used to test: https://github.com/artnaseef/sandbox-log4j.git

To run, mvn clean package then mvn exec:java -Dexec.mainClass=sandbox.log4j.Log4jTest.

Note that the output will look a little garbled because the log4j pattern does not include a newline at the end, making the next line of output, from maven, append to the end of the actual log4j line.

Hope this helps. Based on my experience, the most common cause of log4j output mis-formatting is having more than one log4j configuration file on the classpath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants