Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make log4j to write to the console as well

Is there any way to tell to log4j to write its log to the file and to the console? thanks there are my properties:

log4j.rootLogger=DEBUG,console,R log4j.rootLogger=INFO, FILE  log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Target=System.out log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %m%n  log4j.appender.FILE=org.apache.log4j.RollingFileAppender log4j.appender.FILE.File=log4j.log log4j.appender.FILE.MaxFileSize=512KB log4j.appender.FILE.MaxBackupIndex=3 log4j.appender.FILE.layout=org.apache.log4j.PatternLayout log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p - %m%n 
like image 974
fatnjazzy Avatar asked Aug 01 '10 17:08

fatnjazzy


People also ask

Where does log4j write to?

The Log4j logging settings are stored in the file app_data /conf/server/log4j. properties, where app_data is the application data folder. You can edit this file directly on the server or open it by clicking Settings > Logging.


1 Answers

Your root logger definition is a bit confused. See the log4j documentation.

This is a standard Java properties file, which means that lines are treated as key=value pairs. Your second log4j.rootLogger line is overwriting the first, which explains why you aren't seeing anything on the console appender.

You need to merge your two rootLogger definitions into one. It looks like you're trying to have DEBUG messages go to the console and INFO messages to the file. The root logger can only have one level, so you need to change your configuration so that the appenders have appropriate levels.

While I haven't verified that this is correct, I'd guess it'll look something like this:

log4j.rootLogger=DEBUG,console,file log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.file=org.apache.log4j.RollingFileAppender 

Note that you also have an error in casing - you have console lowercase in one place and in CAPS in another.

like image 51
Steven Schlansker Avatar answered Sep 22 '22 20:09

Steven Schlansker