Sunday, December 18, 2011

Log4j - Child Logs are written in to Parent Log file (for imported child apps)



Log4j Appender: Child Logs are written in to Parent Log file.

<Just scribbling the factors> ...will be edited later.</>
I created one app (say it as a Job) – a stand alone java with logging features through Log4j. I had my own log4j.proeprties with file Appender and my own log file specified.

This job is extracted as Jar and shared with another app (say it as a scheduler). The scheduler loads this Jar (along with many other jars for different Jobs) dynamically through Class Loader.

It also used log4j for logging purpose.

What happened: The logs by the child apps (jobs) where getting written in to the parent (Scheduler) messed up with parent log statements in the parent log file. The child log file was not having any logs written.

This is a known feature as long as the Classloader loads the child apps to one app.

If you need separate logs, the parent log4j.properties has to define another rootLoagger and that logger has to be used in the child logging purpose.. meaning it has got little dependency or coupling b/w parent and child.



No comments:

Post a Comment