• 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

How to... log4j ?

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

I am trying to use log4j in my Struts application. So far I used the "defaults", i.e.

for initializing the logging system and then I used log.info(), log.debug() etc.
The problem is I am getting double posts in my logs. They have the same format, they have the same content. It just logs twice.
Why is this happening ? I searched the net and everything pointed to configuration issues when using custom loggers, but i'm not !
Below is my configuration of log4j.properties:



Any ideas ? Is this the way to use Log4J or do I have to write my own class ?

Thanks a lot !
Dan
[ May 03, 2007: Message edited by: Daniel Platon ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since there is no difference in the way log4j is implemented in a Struts application than it is in any other application I'm moving this to the "Other Frameworks" forum.
[ May 04, 2007: Message edited by: Merrill Higginson ]
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems like you are using quite a old version of log4j.

Anyways I suspect the following might be happening.

If you log a statement from a file say , org.apache.abcd
then it qualifies the first and third category that you have configured in your logger and as both the categories are outputting to the same appender , you might be getting two statements for each log.

The OFF level in the following statement is bothering me.

 
Daniel Platon
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

First of all, why would you say I am using and old version ?
Thanks for your reply Rahul. The OFF level means "absolutely no output" and it works.
I seem to have discovered the problem. I removed the stdout appender from all categories except for the root category and it works now. The problem is I don't know the syntax to make the appenders "not additive" because I don't want the output from my classes to go to stdout

Thanks,
Dan
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason why I said that you are using older version of log4j as in older version category was used and in newer version logger is used.

log4j.category.org.apache.struts=INFO,stdout

should be like,

log4j.logger.org.apache.struts=INFO,stdout

and the additivity you can control using

log4j.additivity.org.apache.struts=true/false
reply
    Bookmark Topic Watch Topic
  • New Topic