Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I have prepared sample code to log all ERROR messages to a single file using Log::Log4perl module.
My question is
How can I simply log all my ERROR messages to different file (according to the date)?
Previously i was harding the error log file path (ie AguLogs.log)
Sample code as follows
#!/usr/bin/perl use Log::Log4perl; Log::Log4perl::init('/root/log4perl.conf'); $log = Log::Log4perl->get_logger(""); $log->debug("Debug message"); $log->info("Info message"); $log->warn("Warn message"); $log->error("Error message");

log4perl.conf file
log4perl.rootLogger=ERROR, LOGFILE log4perl.appender.LOGFILE=Log::Log4perl::Appender::File log4perl.appender.LOGFILE.filename=/root/AguLogs.log log4perl.appender.LOGFILE.mode=append log4perl.appender.LOGFILE.layout=PatternLayout #log4perl.appender.LOGFILE.layout.ConversionPattern= %d %F{1} %c % +p %L> %m %n #log4perl.appender.LOGFILE.layout.ConversionPattern= %d %F{1} %c % +p %m %n log4perl.appender.LOGFILE.layout.ConversionPattern= %d %F{1} %c %p + %m %n

Pls provide a solution to write the log in different file according to the date
Regards,
Sur

Replies are listed 'Best First'.
Re: Log4perl module help
by jdalbec (Deacon) on Aug 14, 2004 at 13:48 UTC
    Log4perl FAQ says:

    What if I need dynamic values in a static Log4perl configuration file?

    Say, your application uses Log::Log4perl for logging and therefore comes with a Log4perl configuration file, specifying the logging behaviour. But, you also want it to take command line parameters to set values like the name of the log file. How can you have both a static Log4perl configuration file and a dynamic command line interface?

    As of Log::Log4perl 0.28, every value in the configuration file can be specified as a Perl hook. So, instead of saying

    log4perl.appender.Logfile.filename = test.log
    you could just as well have a Perl subroutine deliver the value dynamically:
    log4perl.appender.Logfile.filename = sub { logfile(); };
    given that logfile() is a valid function in your main package returning a string containing the path to the log file.

    Or, think about using the value of an environment variable:
    log4perl.appender.DBI.user = sub { $ENV{USERNAME} };
Re: Log4perl module help
by saintmike (Vicar) on Aug 14, 2004 at 23:09 UTC
    Alternatively, use a rolling logfile appender, which will have Log::Log4perl switch automatically to a new logfile every day, named after the current date if you choose so.