On Dec 17, 2004, at 1:10 AM, Manish Moorjani wrote:

Hi All,

 A have a ear, which consist of two components backend and frontend
Package structure is like
Abc.bcd.frontend.*
Abc.bcd.backend.*

I want to log the details of the packages in different log files(using
apache's log4j), can anyone help  me in this?




You asked a log4j question on the log4cxx-user mailing list with a message that contained several hundred lines of list subscription fluff and HTML email. Not a great start.

You should read "A short intro to log4j" at http://logging.apache.org/log4j/docs/manual.html

The quick answer is that you define two file appenders in your configuration, call the backend and frontend and associate each with a corresponding logger with a configuration file like:

log4j.logger.Abc.bdc.frontend=info, frontend
log4j.appender.frontend=org.apache.log4j.FileAppender
log4j.appender.frontend.layout=org.apache.log4j.PatternLayout
log4j.appender.frontend.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.frontend.File=frontend.log
log4j.additivity.frontend=false

log4j.rootLogger=info, backend
log4j.appender.backend=org.apache.log4j.FileAppender
log4j.appender.backend.layout=org.apache.log4j.PatternLayout
log4j.appender.backend.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.backend.File=frontend.log



With this configuration, any logging request submitted to a logger that has a name starting with "Abc.bdc.frontend." will be logged to the frontend.log file. It won't go to backend.log since the loggers additivity is false. Any other logging request, will go the backend.log.

//  would be appended to frontend.log
Logger.getLogger("Abc.bdc.frontend.someclass").info("Some Message");

//  would be appended to backend.log
Logger.getLogger("Abc.bdc.backend.someclass").info("Some Message");



Reply via email to