From: Marco A. V. C. <mav...@bi...> - 2003-12-12 10:24:30
|
Hi All, I've been looking around but could not find a good anwser or guidelines for this. I have log4perl conf file that look like this: log4perl.rootLogger=DEBUG,File log4perl.category.BiT.Inter = INFO log4perl.category.BiT.Inter.Adaptor.bitc2 = FATAL log4perl.category.BiT.Inter.Adaptor.test = DEBUG log4perl.category.BiT.Inter.Adaptor.auth = INFO log4perl.category.BiT.Inter.Adaptor.info = DEBUG log4perl.appender.File = Log::Dispatch::File log4perl.appender.File.filename = /tmp/biti.log log4perl.appender.File.mode = append log4perl.appender.File.layout = \ Log::Log4perl::Layout::PatternLayout log4perl.appender.File.layout.ConversionPattern = %d %C %m %n And there is no problem in here, as expected log4perl logs everything in '/tmp/biti.log'. But as you can see there's BiT.Inter.Adaptor.* classes and they are coded with very different propouses, so have all logs in one file makes more difficult to access/correct some bug. I was thinking in have one file for each Adaptor, but this means write one more Appender configuration for each Adaptor. But I expect more and more Adaptors and as a programmer I'm very lazy, the result I want is that each new adaptor added in my conf file will imply a nre log file with it's name. And other messages to this main log file '/tmp/biti.log' Can anyone point me some thoughts about it? Thanks in advance. Marco. -- Marco A Valtas Cunha http://scarecrow.fmrp.usp.br/~mavcunha/ Lab de Bioinformatica http://bit.fmrp.usp.br Hemocentro de Rib Preto http://ctc.fmrp.usp.br Fax: 55 16 3963-9309 Tel: 55 16 3963-9300 R:9603 |
From: Mike S. <msc...@ao...> - 2003-12-13 04:13:44
|
Marco Aurelio Valtas Cunha wrote on 12/12/2003, 2:24 AM: > I was thinking in have one file for each > Adaptor, but this means write one more Appender configuration for each > Adaptor. > But I expect more and more Adaptors and as a programmer I'm very lazy, > the > result I want is that each new adaptor added in my conf file will > imply a nre > log file with it's name. The file appenders that come with Log::Log4perl and Log::Dispatch require that the name of the file they're logging to is specified as a property -- this leaves you with the manual approach: Define an appender for every file and assign each of them to a different logger (but watch out for messages bubbling up, see the FAQ). If you want to automate the creation of these appenders, you could (somewhat at the expense of the maintainability of your script/config file) leave your config file like it is and use l4p's add_appender() method in your code like this: my $logger = Log::Log4perl->get_logger("My.Component"); $logger->add_appender($app); to add a previously defined appender $app to this logger. Or, you could automate creating the l4p conf file with a script. -- -- Mike Mike Schilli m...@pe... |
From: Marco A. V. C. <mav...@bi...> - 2003-12-20 16:22:37
|
Hi MIke, I've decide go with add_appender() sugestion, since all Adaptors has to inherit from a Adaptor class I've put the code on my construtor. This will make the impact on my maintainability be very small. Since others may have the same problem I'm posting the relevant part of my code for reference. Thanks. Marco. in Adaptor class, which is parent of all Adaptors here is the constructor (comments are in portuguese): sub new { my($caller,$parent) = @_; $logger->logconfess("Missing parent reference") unless $parent; #Load info... $logger->info($caller."->new(".ref($parent).") Version: ". $caller->VERSION." ".$__PACKAGE__::REVISION); # Definindo um arquivo de log separado para cada # adaptador. # # Recuperando o logger do adaptador. my $adpt_logger = Log::Log4perl->get_logger($caller); # Isolando apenas o nome do adaptador. $caller=~m/::([^:]+)$/; my $adpt_name = $1; # Definindo um novo appender para este adaptador. my $file_appender = Log::Log4perl::Appender->new( "Log::Dispatch::File", mode => "append", name => "$adpt_name", filename => "/tmp/biti_$adpt_name.log" ); # Agora o layout deste appender... my $layout = Log::Log4perl::Layout::PatternLayout->new("%d %C %m %n"); $file_appender->layout($layout); $adpt_logger->add_appender($file_appender); # Creating new object... my $self = bless{}, ref($caller) || $caller; $self->{INTER_REF} = $parent; # Our reference to Inter parent. return $self; } Mike Schilli wrote: > Marco Aurelio Valtas Cunha wrote on 12/12/2003, 2:24 AM: > > > I was thinking in have one file for each > > Adaptor, but this means write one more Appender configuration for each > > Adaptor. > > But I expect more and more Adaptors and as a programmer I'm very lazy, > > the > > result I want is that each new adaptor added in my conf file will > > imply a nre > > log file with it's name. > > The file appenders that come with Log::Log4perl and Log::Dispatch > require that the name of the file they're logging to is specified as a > property -- this leaves you with the manual approach: Define an appender > for every file and assign each of them to a different logger (but watch > out for messages bubbling up, see the FAQ). > > If you want to automate the creation of these appenders, you could > (somewhat at the expense of the maintainability of your script/config > file) leave your config file like it is and use l4p's add_appender() > method in your code like this: > > my $logger = Log::Log4perl->get_logger("My.Component"); > $logger->add_appender($app); > > to add a previously defined appender $app to this logger. > > Or, you could automate creating the l4p conf file with a script. > -- Marco A Valtas Cunha http://scarecrow.fmrp.usp.br/~mavcunha/ Lab de Bioinformatica http://bit.fmrp.usp.br Hemocentro de Rib Preto http://ctc.fmrp.usp.br Fax: 55 16 3963-9309 Tel: 55 16 3963-9300 R:9603 |