I'm tried to create multiple log files of different content with log4j.
This is my log4j.properties
file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/home/dhanushka/Documents/log4j.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{1}] %m%n
log4j.appender.testng=org.apache.log4j.RollingFileAppender
log4j.appender.testng.File=/home/dhanushka/Documents/TestNGlog.log
log4j.appender.testng.MaxFileSize=1MB
log4j.appender.testng.MaxBackupIndex=1
log4j.appender.testng.layout=org.apache.log4j.PatternLayout
log4j.appender.testng.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{1}] %m%n
# Direct log messages to 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{ABSOLUTE} %-5p [%c{1}] %m%n
# Root logger option
log4j.rootLogger=INFO, file, admin, stdout, testng
# Log everything. Good for troubleshooting
log4j.logger.org.hibernate=INFO
# Log all JDBC parameters
log4j.logger.org.hibernate.type=ALL
Here is how I implemented in code.
public class VerifyAmenities {
private static Logger defaultLogger = Logger.getLogger("file");
private static Logger testNGlogger = Logger.getLogger("testng");
.
.
}
defaultLogger.info("This is default Logger");
testNGlogger.info("This is testNG Logger");
By this it creates two log files. But Both has same logs. Appreciate any ones reply.