Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the shortest way to get log4j initialized in your main method?

Tags:

java

log4j

I want everything to log to the console and don't want to have to deal with creating log4j.xml files, etc. I am prototyping some libraries and want to see their full log output.

I would like to keep it as pure as possible and not have to introduce unnecessary dependencies like Spring, etc.

like image 434
Nick Stinemates Avatar asked Dec 23 '22 08:12

Nick Stinemates


1 Answers

I use the following:

Logger.getRootLogger().setLevel(Level.ALL);
Layout layout = new PatternLayout("%d [%t] %-5p %c %x - %m%n");
Logger.getRootLogger().addAppender(new ConsoleAppender(layout));
like image 110
idrosid Avatar answered Dec 28 '22 06:12

idrosid