I have a class JLog to log all the messages to a file. The JLog class is in a jx.war file which is deployed to the application server
JBoss.
If the jx.war is deployed once, the messages printed to the file only show up once, which is fine.
But if the jx.war is deployed twice, the messages printed to the file show up twice.
If the jx.war is deployed three times, the messages show up three time and so forth.
My question is why the static object jLogger from the previous deployments doesn't get collected.
How can I solve this problem?
public class JLog {
private static int logLevel = getLogLevel();
private static long line = 0;
static Logger jLogger;
private static PatternLayout jLayout = null;
private static Appender jAppender = null;
public static void toLogger(
String msg ) {
try {
if ( jLogger == null ) {
// System.out.println(" *** get a new logger *** ");
jLogger = Logger.getLogger(JLog.class.getName() );
jLogger.setAdditivity( false );
jLogger.setLevel( Level.ALL );
}
if ( jLayout == null ) {
// System.out.println(" * new patternLayout " );
String
pattern = "%d{yyyy-MM-dd HH:mm:ss,SSS} - %m%n";
jLayout = new PatternLayout( pattern );
pattern = null;
}
if ( jAppender == null ) {
// System.out.println(" * new FileAppender " );
String filename = "jx.log";
String dataPattern = "'.'yyyy-MM-dd";
jAppender = new DailyRollingFileAppender( jLayout, filename, dataPattern );
filename = null;
}
jLogger.addAppender( jAppender );
jLogger.debug( msg );
} catch (Exception e) {
System.out.println("Exception! JLog.toLogger >>> " + e.getMessage() );
e.printStackTrace();
} // try
} // toLogger
:
:
}