-
1. Re: log4j and JBoss
kaobe Jul 8, 2004 10:26 AM (in response to zeron)Hi Zeron,
I don't know if it's the method everyone else uses, but we work with it quite well.
We get a Logger: Logger logger = Logger.getLogger(this.getClass());
We use org.jboss.logging.Logger
With this instance we do all of our logging.
Peter -
2. Re: log4j and JBoss
zeron Jul 19, 2004 5:22 AM (in response to zeron)Hello Peter,
But we have the application already using instances of:
org.apache.log4j.Category ( or org.apache.log4j.Logger) all over the place.
And to tell you the truth, this is working, but in a wierd way:
Once any code that uses logging is run, the server's OWN logging is multiplying like crazy. Instead of one log entry, you get the same log entry up to 20 times!!!
Any clues?? -
3. Re: log4j and JBoss
beked Jul 29, 2004 12:27 PM (in response to zeron)Zeron,
I'm having the same problem as you as my log is being multiplied. Were you able to figure this out?
Thanks,
Josh -
4. Re: log4j and JBoss
john_anderson_ii Aug 3, 2004 6:58 PM (in response to zeron)I am by no means an authority on this subject.
This is kind of a known problem with log4j and application containers. Or, rather, it's not really a problem because this is the expected behavior. Or so I've gathered.
From what I've puzzled out the problem is all about Class loading. When you instatiate a new Logger, it, by default uses the Hierarchy of the logger instantiated above it. Or something close to that anway. The end result is that your application's logging routines are forced into the same sandbox that JBoss's logging routines are in, thus it uses JBoss's appenders, etc..
This cycle can be broken, but bugger me if I've figured out how! You have to deploy your own copy of the log4j.jar file (I think?) with your application. You must then instatiate an instace of the Hierarchy from the context of your application, with a seperate configuration file!
I do not yet have a fully working example, but I'm working hard on it. If anyone beats me to it, please post your work.
Here is the related documentation that really gave me the heads up:
Supporting the log4j RepositorySelector in Servlet Containers -
5. Re: log4j and JBoss
beked Aug 3, 2004 9:04 PM (in response to zeron)I actually did work the problem out. I'm sorry I forgot to post back with what I found....
In my case I did not use log4j. Instead I'm using java.util.logging which I then add a custom JDBC Handler to because I am logging to a DB table rather than a file or the JBoss server log file. Extra handlers where added to my logger because a bean kept adding handlers due to an error in my design and another class that was used kept adding handlers each time it was instantiated.
To fix the problem, I just added the handler the first time the bean object was created. If the bean happened to get created again in anther session, I had placed a check around the addHandler call to make sure the Logger object had no handlers so that the handler would not be added again resulting in multiple calls of the same log statement.
In pseudo code (since I'm not at work):
Logger logger = Logger.getLogger("new");
If (Logger.getHandlers().count == 0)
logger.addHandler(JDBCHandler);
In other words, my guess is that if you are having this problem, somewhere in your code logic you are adding extra handlers to your Logger object. Therefore each time your log statement is multiplied and extra handler of the same type as before has been added to your Logger.
Josh -
6. Re: log4j and JBoss
vashistvishal Aug 5, 2004 3:09 AM (in response to zeron)I i undrestood yr problem correctly, then its an issue with 'additvity' flag inr yr logger configutartion for that looger.
If you set this flag=false then it shouldn't multiply logging in.
like
-------------------
-----------------------------
<appnder-ref ref="xxx"/>