Log::Stamper - generate the formatted stamp for logging
use Log::Stamper; my $stamp = Log::Stamper->new("yyyy-MM-dd"); # Simple time, resolution in seconds my $time = time(); print $stamp->format($time); # 2013-01-13 # if you use milliseconds use Time::HiRes; my $stamp = Log::Stamper->new("HH:mm:ss,SSS"); my ($secs, $msecs) = Time::HiRes::gettimeofday(); print $stamp->format($secs, $msecs); # => "17:02:39,959"
Typically, you would initialize the stamper once and then reuse it over and over again to display all kinds of time values.
Log::Stamper is a formatter which allows dates to be formatted according to the log4j spec on
Log::Stamper
http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
which allows the following placeholders to be recognized and processed:
Symbol Meaning Presentation Example ------ ------- ------------ ------- G era designator (Text) AD e epoch seconds (Number) 1315011604 y year (Number) 1996 M month in year (Text & Number) July & 07 d day in month (Number) 10 h hour in am/pm (1~12) (Number) 12 H hour in day (0~23) (Number) 0 m minute in hour (Number) 30 s second in minute (Number) 55 S millisecond (Number) 978 E day in week (Text) Tuesday D day in year (Number) 189 F day of week in month (Number) 2 (2nd Wed in July) w week in year (Number) 27 W week in month (Number) 2 a am/pm marker (Text) PM k hour in day (1~24) (Number) 24 K hour in am/pm (0~11) (Number) 0 z time zone (Text) Pacific Standard Time Z RFC 822 time zone (Text) -0800 ' escape for text (Delimiter) '' single quote (Literal) '
constractor
return the formatted string
return the code reference for filtering.
use Log::Stamper; my $stamper = Log::Stamper->new( "yyyy", sub { my $str = shift; $str =~ s/0/X/g; return $str; } ); print $stamper->format(time()); # 2X13
Log::Stamper is hosted on github <http://github.com/bayashi/Log-Stamper>
This module was copied from Log::Log4perl::DateFormat to go independent.
Log::Log4perl::DateFormat
Dai Okabayashi <bayashi@cpan.org>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
To install Log::Stamper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Log::Stamper
CPAN shell
perl -MCPAN -e shell install Log::Stamper
For more information on module installation, please visit the detailed CPAN module installation guide.