On Mon, 26 Jan 2009, Manoj Wanzare wrote:
> 3) DEBUG mode should have an option of either writing to Screen
> or debuglog file or both
I presume that 'debug mode' is a mode your application is in, so it
would be available in a variable of the program? If so, you can attach
a filter to each appender and have it check if the appender is supposed
to fire or not:
log4perl.category = DEBUG, Logfile, Screen
log4perl.appender.Logfile = Log::Log4perl::Appender::File
log4perl.appender.Logfile.filename = test.log
log4perl.appender.Logfile.layout = \
Log::Log4perl::Layout::SimpleLayout
log4perl.appender.Logfile.Filter = LogFileFilter
log4perl.appender.Screen = Log::Log4perl::Appender::Screen
log4perl.appender.Screen.layout = \
Log::Log4perl::Layout::SimpleLayout
log4perl.appender.Screen.Filter = ScreenFilter
log4perl.filter.ScreenFilter = \
sub { my %p = @_; $p{log4p_level} eq "INFO" or $main::debug_mode_to_screen }
log4perl.filter.LogFileFilter = \
sub { my %p = @_; $p{log4p_level} eq "INFO" or $main::debug_mode_to_file }
The Log::Log4perl::Filter docs show more details. You probably want to
write a custom Log::Log4perl::Filter to keep the filter logic separate
from the Log4perl configuration file. In the config above, if you set
our $debug_mode_to_screen = 0;
our $debug_mode_to_file = 0;
in the main program, nothing will happen with debug messages (but still
with info messages).
> 4) Option to replicate debug log messages in system-wide
> logging if debug log is turned of.
Hmm, I need some clarification on this one -- what exactly do you want
to replicate?
-- Mike
Mike Schilli
m...@pe...
> I am a new user of log4perl and to this mailing list. I am working
> on a perl project - want to incorporate Log4perl as main logging
> framework. The requirement is as below:
>
> 1) Wrapper over Log4perl
> 2) System-wide Logging to File & Screen in INFO mode
> 3) DEBUG mode should have an option of either writing to Screen
> or debuglog file or both
> 4) Option to replicate debug log messages in system-wide
> logging if debug log is turned of.
>
> Creating a package and using a log4 conf file with rootLogger in
> INFO mode and Logfile and Screen as appenders take care of
> requirement 1&2 however option third and fourth is tricky to
> incorporate. I have tried Filter match etc but cannot seem to get
> my head around effectively incorporating requirement 3 & 4.
|