java - Log4j terminal logs are executing but No Output file -
while executing application, show logs in eclipse ide's console. it's not writing data on external log file
created simple application adding log4j logs.
code
import org.apache.log4j.logger; public class helloexample{ final static logger logger = logger.getlogger(helloexample.class); public static void main(string[] args) { helloexample obj = new helloexample(); obj.runme("milinda"); } private void runme(string parameter){ if(logger.isdebugenabled()){ logger.debug("this debug : " + parameter); } if(logger.isinfoenabled()){ logger.info("this info : " + parameter); } logger.warn("this warn : " + parameter); logger.error("this error : " + parameter); logger.fatal("this fatal : " + parameter); } }
my log4j porperty file bellow
log4j.rootlogger=error, stdout log4j.appender.stdout=org.apache.log4j.consoleappender log4j.appender.stdout.target=system.out log4j.appender.stdout.layout=org.apache.log4j.patternlayout log4j.appender.stdout.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l - %m%n log4j.appender.file=org.apache.log4j.rollingfileappender log4j.appender.file.file=c:\\projects\\hellologging\\test.log log4j.appender.file.maxfilesize=5mb log4j.appender.file.maxbackupindex=10 log4j.appender.file.layout=org.apache.log4j.patternlayout log4j.appender.file.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l - %m%n
you need add file appender rootlogger. try this...
log4j.rootlogger=error, stdout, file <-- added file here log4j.appender.stdout=org.apache.log4j.consoleappender log4j.appender.stdout.target=system.out log4j.appender.stdout.layout=org.apache.log4j.patternlayout log4j.appender.stdout.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l - %m%n log4j.appender.file=org.apache.log4j.rollingfileappender log4j.appender.file.file=c:\\projects\\hellologging\\test.log log4j.appender.file.maxfilesize=5mb log4j.appender.file.maxbackupindex=10 log4j.appender.file.layout=org.apache.log4j.patternlayout log4j.appender.file.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l - %m%n
Comments
Post a Comment