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

I am using Log::Log4perl in an application and I'd like to configure it in a way that it will log every call DEBUG or higher with limited information while calls that are ERROR or more serious will also include a stack trace. To include a stack trace I can add %T to the layout.ConversionPattern of the logger but so far I have not managed to configure it so both cases will work.

As a secondary issue, the %T tag prints the stack trace as a single line which makes it hard to read. Any idea how to convince the logger to print every level in the stack on a separate line?

  • Comment on Different log layout based on level using Log::Log4perl

Replies are listed 'Best First'.
Re: Different log layout based on level using Log::Log4perl
by Khen1950fx (Canon) on Sep 14, 2010 at 13:32 UTC
    I would use two separate loggers that make use of different appenders that write to the same file name. For example, here would be my conf:
    Log::Log4perl Conf log4perl.logger.my_app = DEBUG, LOG1 log4perl.appender.LOG1 = Log::Log4perl::Appender::File log4perl.appender.LOG1.filename = /var/log/mylog.log log4perl.appender.LOG1.mode = append log4perl.appender.LOG1.layout = Log::Log4perl::Layout::PatternLayout log4perl.appender.LOG1.layout.ConversionPattern = %d %p %T - %m%n log4perl.logger.my_other_app = ERROR, LOG2 log4perl.appender.LOG2 = Log::Log4perl::Appender::File log4perl.appender.LOG2.filename = /var/log/mylog.log log4perl.appender.LOG2.mode = append log4perl.appender.LOG2.layout = Log::Log4perl::Layout::PatternLayout log4perl.appender.LOG2.layout.ConversionPattern = %d %p %T - %m%n
Re: Different log layout based on level using Log::Log4perl
by Anonymous Monk on Sep 14, 2010 at 19:23 UTC