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 |