|Do you know where your variables are?|
Re^2: Log4perl "multiple categories"?by leriksen (Curate)
|on Mar 02, 2006 at 04:15 UTC||Need Help??|
This entry only address the question of category construction and usage, not the OP's question of several active categories. I need to think about that some more.
my usual retrieval of the logging instance is
my $logger = get_logger((caller(0)));
so my log entries usually look like
2006/03/02 14::55::53 DataMatrix.Encoders.asciiEncoder - DEBUG - data is 99ABC00
Pattern in log.conf for the layout for me is usually
Creating the category this way means the category is the fully qualified name of the current function/method. I usually dont include the line numbe, because it just makes the log line longer, and my functions/methods are usually between 5-20 lines
This means I can activate the logger in a single function in a package with the following config line
I can activate every logger in a package with
And I can activate the logging in the entire application with
I can even activate a highly specific logger deep in a function this way
Match that with a config file directive like this
and you can comment out this line to not see this logging, or uncomment to activate it. This technique is especially powerful if the deep logger is inside several loops, and its quite voluminous.
If you start the application with that line in the log config commented out, you wont see anything. If your initialisation of Log4 perl is by using
then you can start the app, and uncomment the line, wait $delay seconds for the logging to start, comment out the line again and wait upto $delay seconds for it to stop again. Or you could setup a signal handler to toggle the activation of a logging category in response to you sending a SIGUSR1 to the applications process - we've used this technique when debugging DBI SQL problems. Application normally has quiencent logging, but we can activate logging for a single running instance of that application by sending it a signal. Better than all the logging starting for your running processes that share a config file!
...reality must take precedence over public relations, for nature cannot be fooled. - R P Feynmann