简体   繁体   中英

How to make the logs to an ouput file in java

I manage the logs of my maven project with Logger org.apache.log4j.Logger

This is an example:

public transient Logger log = CommonLogger.getLogger(this.getClass());


log.info("start of : " + this.getClass().getSimpleName() + " : " + methodName);

So as you khnow the code above helps to show the log in the consol of eclipse but i want to export that logs shown on the consol dynamically to a file in a personalized location.

Define a log4j.properties file in the project classpath.

log4j.rootLogger=INFO, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\logs\\impalalog.log
log4j.appender.file.MaxFileSize=10MB
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM