From: <tod...@ex...> - 2004-12-13 19:54:19
|
Im trying to set dynamic PallernLayouts depending on the log level called. Using my current logger, call $log->enter and $log->exit at the beginning and end of my subroutines. I then generate XML using XML::Writer in my logging routines. This XML is transformed using an XSLT stylesheet to give different views of the logged data. It works great, but I need to extend it to provide multiple channels. To get the ->enter and ->exit routines, I used: L::L4p::Logger::create_custom_level("ENTER", "FATAL"); L::L4p::Logger::create_custom_level("EXIT", "ENTER"); I set my config as follows: l4p.a.myLW.layout = Log::Log4perl::Layout::PatternLayout l4p.a.myLW.layout.ConversionPattern = <%p>(%M)%m</%p>%n What I cant figure out is how to change the ConversionPattern dynamically when either ->enter or ->exit is called. I can figure out HOW, I found http://search.cpan.org/~mschilli/Log-Log4perl-0.49/eg/override_appender I cant figure out where to put the following code: sub enter { my $self = shift; my $appenders = Palace::Log::Log4perl->appenders(); my $hold = $appenders->{PalaceLogWriter}->layout(); my $layout = __PACKAGE__->new('<function name="%M" docUri="%M">%n'); $appenders->{PalaceLogWriter}->layout($layout); $Log::Log4perl::caller_depth++; $self->extra( @_ ); $Log::Log4perl::caller_depth--; $appenders->{PalaceLogWriter}->layout($hold); } sub exit { my $self = shift; my $appenders = Palace::Log::Log4perl->appenders(); my $hold = $appenders->{PalaceLogWriter}->layout(); my $layout = __PACKAGE__->new('</function>%n'); $appenders->{PalaceLogWriter}->layout($layout); $Log::Log4perl::caller_depth++; $self->extra( @_ ); $Log::Log4perl::caller_depth--; $appenders->{PalaceLogWriter}->layout($hold); } Ive tried overloading the ->log() method of my appender and overloading the ->render() method of PatternLayout. The closest I ever got was calling the ->define() method in my ->render() method and the setting $self->{printformat} back to its old value, after calling ->SUPER::render(), but I got strange results. Any assistance will be appreciated, Todd W. _______________________________________________ Join Excite! - http://www.excite.com The most personalized portal on the Web! |