1
votes

I am using log4j logging and am trying to log to different log files. I also want to be able to show the class names in the different log files. How do I instantiate my 2 different log files : serverFileLog and clientLogger. I need to pass in the class name so the call to get logger I can't use the logger name. Please HELP|!!!!!! Thank you!!

log4j.rootLogger=DEBUG, serverFileLog

Server File Log

log4j.appender.serverFileLog=org.apache.log4j.RollingFileAppender log4j.appender.serverFileLog.File=./ServerLog.log log4j.appender.serverFileLog.layout=org.apache.log4j.PatternLayout log4j.appender.serverFileLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n log4j.additivity.serverFileLog=false

Client File Log

log4j.appender.clientLog=org.apache.log4j.FileAppender log4j.appender.clientLog.File=./Client.log log4j.appender.clientLog.layout=org.apache.log4j.PatternLayout log4j.appender.clientLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n log4j.category.clientLogger=DEBUG, clientLog log4j.additivity.clientLogger = false

1
Yes I got my log files working except for this new problem of how to specify the class in the logs.user565660
use %c only to print fully qualified class nameNullPointerException
To instantiate log files I have to do a Logger.getLogger("clientLogger"); to get the client logger. This will use client logger as the class name in log file. I really need to do Logger.getLogger(Client.class) so that it uses the class name. But how do I get the correct logger client logger? I am going to have other classes within the client so I cant just use the logger name.user565660

1 Answers

2
votes

Maybe it's too late to answer now, but I've just found the answer. Hope it can help you. You should use: Logger.getLogger("clientLogger.ClassName") instead of Logger.getLogger("clientLogger")