Log to console only
# Set root logger log4j.rootLogger=DEBUG, console # Add log messages to console 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} %-5p %c - %m%n
Log to file only
# Root logger option log4j.rootLogger=DEBUG, file # File appender log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n log4j.appender.file.File=myoutput.log log4j.appender.file.MaxFileSize=100KB
Log to both console and file
# Root logger option log4j.rootLogger=DEBUG, file, console # Direct log messages to stdout 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} %-5p %c - %m%n # File appender log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c - %m%n log4j.appender.file.file=myoutput.log log4j.appender.file.MaxFileSize=100KB
Log to both console and file and with different log levels
# Root logger option log4j.rootLogger=TRACE, file, console # Direct log messages to stdout 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} %-5p %c - %m%n log4j.appender.console.Threshold=TRACE # File appender log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c - %m%n log4j.appender.file.file=myoutput.log log4j.appender.file.MaxFileSize=100KB log4j.appender.file.Threshold=DEBUG
Log to console and customize level based on package
# Set root logger log4j.rootLogger=TRACE, console # Add log messages to console 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} %-5p %c - %m%n log4j.logger.com.sourcetricks=DEBUG
0 comments:
Post a Comment