Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

potyl (8582)

  (email not shown publicly)

Journal of potyl (8582)

Monday September 28, 2009
01:46 PM

Log::Log4perl now supports %R

[ #39688 ]

Log::Log4perl 1.25 has been released and it has two interesting enhancements:

  • Color configuration and attribute support added to ScreenColoredLevels
  • Patternlayout now supports %R, which returns the time elapsed from the last logging event

The first enhancement looks really nice but I didn't had the opportunity to try it yet. I really like to use the color appender yet I always found the default color choice a bit odd. I used to work around this by creating a custom profile for my terminal with colors that matched the Log4perl log levels and fixed them to my liking. It's a bit hackish but on the other hand not everyone has the same color tastes.

I can comment a bit more on the second addition to Log4perl: the format %R in Patternlayout. This format is very similar to %r which prints the time elapsed since the start of the program except that %R prints the time elapsed since the last event successful logged event. This is exactly the same functionality as Log::Log4perl::Layout::PatternLayout::Elapsed but now available out of the box with Log::Log4per!

I got used to employ %r in my console appender while developing scripts. This was nice as I could see the execution time of the program and find the program's hot spots as I developed. I have to agree that this doesn't replace a good profiler but you will be surprised of the results.

The problem with %r is that finding the time elapsed between two consecutive log events requires compute the time difference between each consecutive log event. This can be easily done with another Perl script that will parse the output and show the time elapsed between each log event.

While parsing the output of a program with another program works, specially in Linux/Unix where pipes are so easy to do, it still wasn't the right thing to do. That's why I wrote Log::Log4perl::Layout::PatternLayout::Elapsed a long time ago. This allowed me to use that same functionality but from all programs using Log4perl without requiring to pipe the output through another program.

I'm glad to see that the modification is now in Log4perl and that I will be able to use without this feature right straight from Log4perl!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.