• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

log4j logging twice

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I see log4J logging the same information twice.

I call a method ( pasted below ). the method returns me a myLogger which is a instance of the log4j Logger
then I do a

myLogger.fatal(myAct.createStringForFileLogging(stepName));

I do this in a MDB. Also if myLogger is not null, I use myLogger as is

this is how I get the logger

String logPattern = "%m%n";
String datePattern = "'.'yyyy-MM-dd"
Logger myLogger = null;
DailyRollingFileAppender logFile = null;
logFile = new DailyRollingFileAppender(new PatternLayout(logPattern),logFileName, datePattern);
myLogger = Logger.getLogger(loggerName);
myLogger.addAppender(logFile);
myLogger.setLevel(Level.DEBUG);
return myLogger;

Appreciate help on this. Its been driving me crazy
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like an additivity issue. If the specified logger and the root logger both log it you can end up with dups. You could try setting additivity to false on your logger. Log4j manual mentions additivity and has a link to API with the method setAdditivity().

I don't normally configure anything in code, have always used properties files. I tried coding exactly what you said and I didn't get duplicate messages; you may have other configuration elsewhere in your code (like for root logger?). I had to make a couple thing up and I added to the logPattern so I could see the timestamp, level, loggername.


[ March 11, 2005: Message edited by: Carol Enderlin ]
 
Mahesh Trikannad
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Carol,

I had tryed the additivity thingy, but that was not it.

As it turned out, when I made the Logger variable static, it worked Ok.

Previously every MDB instance had its own, Logger variable.
I was under the impression, the getLogger(loggerName) , would return a singleton.

Guess I still dont really understand, why creating 2 different logger variables, and using one to log something, actually logs it twice.

Appreciate your insights

Regards

Mahesh
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mahesh,

This kind of things happen because of class loaders. If you calling getLogger method from ejbs and jsps, it will create two different instances of loggers as both classloaders are different.

Vaibhav
 
reply
    Bookmark Topic Watch Topic
  • New Topic