From: Jim C. <jc...@di...> - 2003-07-09 17:00:50
|
Mike Schilli wrote: >On Tue, 8 Jul 2003, Vince Veggus wrote: > > > >>I want my module a.pm to log into a.log, b.pm into b.log. >>I call init(a.conf) and getLogger() in the Constructor of a. >>I call init(b.conf) and getLogger() in the Constructor of b. >>My run.pl uses a and b, a->run() an b->run() log something into >>a.log and b.log. >> >> >> Youve implied that you want b.pm writing to b.log, irrespective of whether its being used by X.pl or Y.pl. This may be unwise; your logs could be incomprehensible if X and Y (or even X and X) are run simultaneously. You may find them more useful if; theyre keyed to the executable name, theyre datestamped, one log-file per run. (assuming 2 progs in under second is unlikely) the following does this - it extracts the logfile name from $0, so the same config can be used from all your tools. log4perl.appender.MainLog.filename = sub { \ my $n = $0; \ $n =~ s|.*/||; \ $n =~ s/(\.(t|pl))?$//; \ $d = strftime "$format", scalar localtime; return "./$n.$d.log";\ } You can play similar tricks in choosing which log-config file to load, based upon value of $0, or of cmdline option. >But after calling a->run() b->run() logs into a.log too. > > you might just raise level of the root logger, so it doesnt print anything, then have a-logger and b-logger be siblings, rather than one also being root logger. |