I'm reading up on Log4perl and want to try and use it for simple log management of my Perl scripts running on a Linux box. I've also read up on newsyslog
and logrotate
but want to use Log4perl if at all possible.
I'm trying to configure the /etc/log4perl.conf
file so that it:
- Defines a
widget
logger (INFO
level) that will write all output to/opt/myapp/logs/myapp-<datetime>.log
, where<datetime>
is a date/time formatted string like2012-12-20
- This
myapp-<datetime>.log
file needs to be rotated daily (preferably at midnight), where the old file is deleted, and a new file is created with<datetime> + 1
. For instance,myapp-2012-12-20.log
would be replaced withmyapp-2012-12-21.log
, etc.
Here's my best attempt which I believe is close, but is still missing some configuration:
#####/etc/log4perl.conf############################################################
log4perl.logger.widget = INFO, MyAppLogAppender
log4perl.appender.MyAppLogAppender = Log::Log4perl::Appender::File
log4perl.appender.MyAppLogAppender.filename = /opt/myapp/logs/myapp-???.log
log4perl.appender.MyAppLogAppender.layout = Log::Log4perl::Layout::SimpleLayout
###################################################################################
How do I configure log4perl.appender.MyAppLogAppender
to rotate once a day, delete the old file, and create a new one with a correct timestamp? Thanks in advance.