|Perl Monk, Perl Meditation|
Re: using log4perlby andreychek (Parson)
|on Sep 04, 2003 at 17:44 UTC||Need Help??|
Log::Log4perl is an excellent tool to use, and you seem to be on the right track. Log4perl allows you to use a heirarchy, similar to classes in OO programming. Your first line in your config file, with the word "rootLogger" in it, is at the top of the heirarchy. What Log4perl does, is any time a child logger logs a message, no matter what log level it was at when it was logged, that message is automatically given to all the parent loggers to be logged. The second line in your config file is setting up, a child logger.. sort of.
So that's exactly your problem -- messages are being logged at the INFO level, Log4perl says "Oh goody, this logger has parents!", and Log4perl gives the messages to the parents to log, as well as the child. Alas, it then gets logged in both places, which isn't what you want in this case.
I might recommend setting up different categories. What's going on becomes a little more obvious, and the actual problem is a bit easier to see. To do that, we'll get rid of the first two lines of your config file:
And we'll put this in it's place:log4perl.logger.SomeCategory=FATAL, A1, Mailer
Of course, instead of "SomeCategory" and "AnotherCategory", you should use names which would be useful to you :-)
What we've is seperate your two loggers into seperate categories. They are no longer related, and we won't have a problem with duplicate messages. But your Perl code will have to change a bit to make use of these new categories. It's simply, and would just look like this:
There are times when you don't want to use unrelated categories. Categories are quite useful, and often you do want to set up a heirarchy of some sort. To prevent duplicate logs in that case, you can do any of the following:
If you haven't already, I highly recommend reading the Log4perl tutorial on Perl.com. It goes over a few of the Log4perl traps, and offers some excellent examples of usage.Good luck!
Lucy: "What happens if you practice the piano for 20 years and then end up not being rich and famous?"
Schroeder: "The joy is in the playing."