How to make reading log4perl output easier?

When using log4perl, the debug log layout I am using is:

log4perl.appender.D10.layout=PatternLayout log4perl.appender.D10.layout.ConversionPattern=%d [pid=%P] %p %F{1} (%L) %M %m%n log4perl.appender.D10.Filter = DebugAndUp 

This creates very detailed debug logs, for example:

 2008/11/26 11:57:28 [pid=25485] DEBUG SomeModule.pm (331) functions::SomeModule::Test Test XXX was successfull 2008/11/26 11:57:29 [pid=25485] ERROR SomeOtherUnrelatedModule.pm (99999) functions::SomeModule::AnotherTest AnotherTest YYY has faled 

This works great and provides excellent debugging data.

However, each line of the debug log contains different function names, pid length, etc. This makes the difference between each line and makes reading debug logs much more difficult than necessary.

Is there a way in log4perl to format the string so that debug metadata (everything up to the actual log message) is filled with spaces / tabs at the end and do the actual messages start in one column of text?

+4
source share
2 answers

You can fill out the individual fields that make up your entries. For example, [pid =% 5P] will always give you at least 5 characters for the PID.

"Define placeholders for placeholders" in the docs for Log :: Log4perl :: Layout gives more details.

+8
source

There are several ways to do this, although you need to figure out which one is best for your situation:

  • Use a different application if you are working live. Ask this application to use a template that displays only the information you need. For example, if you are working in the same process, your alternate appender may leave the PID and timestamp. You may need only the file name and line number.

  • Use %n to set new lines in the right place. This makes multiline output, which is a bit more difficult to parse later, but you can choose a different sequence for the input separator (for example, the literal "[EOL]") to make reading input line by line easier.

  • Enter the database instead of the file. For your reports, select only the columns that you want to check.

  • Record everything, but write a filter to view the ad-hoc log file, to display only those parts that you want to see, for example, only debug messages, records between certain moments, only records containing a file, etc.

+5
source

All Articles