I use apache log4j for my application logging. I use log4j.xml to initialize the loggers when my application server starts. For each class, I invoke Loggers.getLogger("loggername") to get the logging instance to log details of that class.
For example: in log4j.xml
<appender name="default" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${log.dir}/logs/serverout.txt" />
<param name ="Append" value="TRUE"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{[HH:mm:ss:SSS]|[MM-dd-yyyy]}|[%c]|[%p]|[%L]: %m|%n"/>
</layout>
<param name="MaxFileSize" value="10MB"/>
<param name="MaxBackupIndex" value="100"/>
</appender>
<logger name="com.mypackage" additivity="false">
<level value="INFO"/>
<appender-ref ref="default"/>
</logger>
And how I invoke in each class
private static Logger logger = Logger.getLogger(MPMyclass.class.getName());
My requirement: Basically, I run an application server when there would be many user sessions. Each session has a unique sessionId. Each session is an instance of several classes. Each class has its own instance of Logger. If I want to enable log level for a particular class (MPMyclass) .. I can just get the logger name(com.mypackage) and set its level so that it changes the level overall. But I want it in a way so that I can set only to a particular session not overall. If I have a class name MPMyclass , there are many instance of MPMyclass, my requirement is to change the logger level of an instance of that class not all instance.
Possible solution: 1. Each session/instance has a unique sessionId. So I can get/set levels. But this is too much complicated as there are many classes it would be clumsy to set/get. 2. I can have a Hashtable to store each instance of class with their unqiue sessionid, but it is also not recommended as there are too many classes and instance of classes it is deftly not a good soln.
I am working on to solve this with simple solution with the help of log4j or through Java design. Please suggest me if there is anything that I can work on.
Thanks