You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
(38) |
Sep
(126) |
Oct
(23) |
Nov
(72) |
Dec
(36) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(76) |
Feb
(32) |
Mar
(19) |
Apr
(6) |
May
(54) |
Jun
(40) |
Jul
(45) |
Aug
(35) |
Sep
(51) |
Oct
(67) |
Nov
(10) |
Dec
(50) |
2004 |
Jan
(51) |
Feb
(22) |
Mar
(22) |
Apr
(28) |
May
(53) |
Jun
(99) |
Jul
(38) |
Aug
(49) |
Sep
(23) |
Oct
(29) |
Nov
(30) |
Dec
(48) |
2005 |
Jan
(15) |
Feb
(21) |
Mar
(25) |
Apr
(16) |
May
(131) |
Jun
|
Jul
(8) |
Aug
(5) |
Sep
(15) |
Oct
|
Nov
(15) |
Dec
(12) |
2006 |
Jan
(15) |
Feb
(20) |
Mar
(8) |
Apr
(10) |
May
(3) |
Jun
(16) |
Jul
(15) |
Aug
(11) |
Sep
(17) |
Oct
(27) |
Nov
(11) |
Dec
(12) |
2007 |
Jan
(19) |
Feb
(18) |
Mar
(33) |
Apr
(4) |
May
(15) |
Jun
(22) |
Jul
(19) |
Aug
(20) |
Sep
(14) |
Oct
(4) |
Nov
(34) |
Dec
(11) |
2008 |
Jan
(8) |
Feb
(18) |
Mar
(2) |
Apr
(4) |
May
(26) |
Jun
(9) |
Jul
(8) |
Aug
(8) |
Sep
(3) |
Oct
(17) |
Nov
(14) |
Dec
(4) |
2009 |
Jan
(6) |
Feb
(41) |
Mar
(21) |
Apr
(10) |
May
(21) |
Jun
|
Jul
(8) |
Aug
(4) |
Sep
(3) |
Oct
(8) |
Nov
(6) |
Dec
(5) |
2010 |
Jan
(14) |
Feb
(13) |
Mar
(7) |
Apr
(12) |
May
(4) |
Jun
(1) |
Jul
(11) |
Aug
(5) |
Sep
|
Oct
(1) |
Nov
(10) |
Dec
|
2011 |
Jan
(7) |
Feb
(3) |
Mar
(1) |
Apr
(5) |
May
|
Jun
(1) |
Jul
(6) |
Aug
(6) |
Sep
(10) |
Oct
(5) |
Nov
(4) |
Dec
(5) |
2012 |
Jan
(4) |
Feb
(5) |
Mar
(1) |
Apr
(7) |
May
(1) |
Jun
|
Jul
(2) |
Aug
|
Sep
(5) |
Oct
(5) |
Nov
(4) |
Dec
(5) |
2013 |
Jan
(6) |
Feb
|
Mar
(14) |
Apr
(9) |
May
(3) |
Jun
(2) |
Jul
(1) |
Aug
(1) |
Sep
|
Oct
|
Nov
(4) |
Dec
(6) |
2014 |
Jan
|
Feb
(1) |
Mar
(10) |
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
(1) |
Nov
|
Dec
(4) |
2015 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
From: Kevin G. <ke...@go...> - 2002-09-09 19:21:40
|
Sorry, Hugh, we haven't implemented anything comparable to LevelMatchFilter yet. Actually, I don't think we've done anything with Filters at all yet. Keep checking back, though, or feel free to suggest an implementation yourself. Hugo Salgado wrote: > Hi, i'd like to use this feature of log4j, but in > the perl version. How can i do it ?? > ----- From log4j FAQ > Is it possible to direct log output to different appenders by level? > Yes it is. Setting the Threshold option of any appender extending > AppenderSkeleton, (most log4j appenders extend AppenderSkeleton) to > filter out all log events with lower level than the value of the > threshold option. > For example, setting the threshold of an appender to DEBUG also allow > INFO, WARN, ERROR and FATAL messages to log along with DEBUG messages. > This is usually acceptable as there is little use for DEBUG messages > without the surrounding INFO, WARN, ERROR and FATAL messages. Similarly, > setting the threshold of an appender to ERROR will filter out DEBUG, > INFO and WARN messages but not ERROR or FATAL messages. > This policy usually best encapsulates what the user actually wants to > do, as opposed to her mind-projected solution. > See examples/sort4.lcf for an example threshold configuration. > If you must filter events by exact level match, then you can attach a > LevelMatchFilter to any appender to filter out logging events by exact > level match. > ------- > Thanks, > Hugo > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > log4perl-devel mailing list > log...@li... > https://lists.sourceforge.net/lists/listinfo/log4perl-devel -- Happy Trails . . . Kevin M. Goess (and Anne and Frank) 904 Carmel Ave. Albany, CA 94706 (510) 525-5217 |
From: Hugo S. <hsa...@vu...> - 2002-09-09 19:12:22
|
Hi, i'd like to use this feature of log4j, but in the perl version. How can i do it ?? ----- From log4j FAQ Is it possible to direct log output to different appenders by level? Yes it is. Setting the Threshold option of any appender extending AppenderSkeleton, (most log4j appenders extend AppenderSkeleton) to filter out all log events with lower level than the value of the threshold option. For example, setting the threshold of an appender to DEBUG also allow INFO, WARN, ERROR and FATAL messages to log along with DEBUG messages. This is usually acceptable as there is little use for DEBUG messages without the surrounding INFO, WARN, ERROR and FATAL messages. Similarly, setting the threshold of an appender to ERROR will filter out DEBUG, INFO and WARN messages but not ERROR or FATAL messages. This policy usually best encapsulates what the user actually wants to do, as opposed to her mind-projected solution. See examples/sort4.lcf for an example threshold configuration. If you must filter events by exact level match, then you can attach a LevelMatchFilter to any appender to filter out logging events by exact level match. ------- Thanks, Hugo |
From: Kevin G. <ke...@go...> - 2002-09-09 17:54:20
|
Mike, did you diff the website patch that works against the email patch that doesn't? They both come out the same to me. msc...@ao... wrote: >>Maybe Mozilla is doing weird stuff... anyway, I >>re-confirmed that the patch works. But to make life >>easy, I put it up on my website. > > > Interesting. Can you confirm the patch works even after you send mail to yourself? > > Anyway, the patch on your website worked (yay!) like a charm. Couple of questions/requests on your changes: > > * Looks like the error message here got garbeled (Logger.pm): > > my $after = shift || die("create_custom_level: forgot to pass in an after string! > > * What's the purpose of > > our %PRIORITY = (); # unless (%PRIORITY); > our %LEVELS = () unless (%LEVELS); > our %SYSLOG = () unless (%SYSLOG); > > And why the '#' in the first line? > > * Documentation: Can you add a couple of lines to Log::Log4perl.pm to show how to use the custom level features? > > * Why the logic > > # figure out new int value by AFTER + (AFTER+ 1) / 2 > > if you could just store the priorities defined so far orderly in an array and switch to the next/previous element? > > * # This is a bit better way to create code on the fly than eval'ing strings. > # -erik > > Nice. Does this mean they're (-d) debuggable now? Could we go all the way and use this in set_output_methods() as well? > > Looks like your foreach loop is outside the subroutine and therefore only called when the module is loaded: > > #now lets autogenerate the logger subs based on the defined priorities > foreach my $level (keys %Log::Log4perl::Level::PRIORITY){ > create_log_level_methods($level); > } > > Would be great if you could shed some light on these > issues ... :) > > -- Mike > > Mike Schilli > log...@pe... > http://perlmeister.com > > > ------------------------------------------------------------------------ > > Subject: > Re: Release 0.23 because of upcoming article? > From: > er...@se... > Date: > Sun, 08 Sep 2002 20:50:42 -0700 > To: > "Erik W. Selberg" <er...@se...> > > > > Maybe Mozilla is doing weird stuff... anyway, I re-confirmed that the > patch works. But to make life easy, I put it up on my website. > > http://speedstation.whizzyfoo.com/Log-Log4perl/custlevel3.patch > > Note: Log4perl.patchable is just a copy of a fresh checkout. > > 121 speedstation:Log-Log4perl.patchable >patch -p0 < ../custlevel3.patch > patching file lib/Log/Log4perl/Appender.pm > patching file lib/Log/Log4perl/Level.pm > patching file lib/Log/Log4perl/Logger.pm > patching file t/001Level.t > patching file t/002Logger.t > patching file t/016Export.t > patching file t/024WarnDieCarp.t > patching file t/025CustLevels.t > 122 speedstation:Log-Log4perl.patchable > > > -e > > Erik W. Selberg wrote: > >> Hmm.... that's what I did. >> >> Well, here goes again. Can ya let me know what the output of patch is >> if it doesn't go through? >> >> Thanks, >> -e >> >> msc...@ao... wrote: >> >>> In a message dated Sun, 8 Sep 2002 4:31:30 AM Eastern Standard Time, >>> er...@se... writes: >>> >>> >>> >>>> Please apply the patch.. >>>> >>> >>> >>> >>> Ok ... just tried to apply your latest patch, unfortunately it >>> doesn't go through -- maybe it's my email client mangling the lines, >>> so please >>> >>> 1) use "cvs diff -Nau" of your local dir against CVS >>> 2) send the patch as an attachment >>> >>> Thanks! >>> >>> -- Mike >>> >>> Mike Schilli >>> log...@pe... >>> http://perlmeister.com >>> >>> >>> >> >> >> ------------------------------------------------------------------------ >> >> ? out.txt >> Index: lib/Log/Log4perl/Appender.pm >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Appender.pm,v >> retrieving revision 1.8 >> diff -a -u -r1.8 Appender.pm >> --- lib/Log/Log4perl/Appender.pm 21 Aug 2002 07:52:51 -0000 1.8 >> +++ lib/Log/Log4perl/Appender.pm 9 Sep 2002 02:11:14 -0000 >> @@ -83,8 +83,9 @@ >> >> # Check if the appender has a last-minute veto in form >> # of an "appender threshold" >> - if($self->{level} < $ >> + if($self->{level} > $ >> Log::Log4perl::Level::PRIORITY{$level}) { >> + print "$self->{level} > $level, aborting\n" if DEBUG; >> return; >> } >> >> Index: lib/Log/Log4perl/Level.pm >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Level.pm,v >> retrieving revision 1.6 >> diff -a -u -r1.6 Level.pm >> --- lib/Log/Log4perl/Level.pm 3 Sep 2002 18:12:17 -0000 1.6 >> +++ lib/Log/Log4perl/Level.pm 9 Sep 2002 02:11:16 -0000 >> @@ -7,22 +7,44 @@ >> use warnings; >> use Carp; >> >> +# log4j, for whatever reason, puts 0 as all and MAXINT as OFF. >> +# this seems less optimal, as more logging would imply a higher >> +# level. But oh well. Probably some brokenness that has persisted. :) >> +use constant ALL_INT => 0; >> +use constant DEBUG_INT => 10000; >> +use constant INFO_INT => 20000; >> +use constant WARN_INT => 30000; >> +use constant ERROR_INT => 40000; >> +use constant FATAL_INT => 50000; >> +use constant OFF_INT => (2 ** 31) - 1; >> + >> no strict qw(refs); >> +use vars qw(%PRIORITY %LEVELS); >> + >> +our %PRIORITY = (); # unless (%PRIORITY); >> +our %LEVELS = () unless (%LEVELS); >> +our %SYSLOG = () unless (%SYSLOG); >> + >> +sub add_priority { >> + my ($prio, $intval, $syslog) = @_; >> + $prio = uc($prio); # just in case; >> + >> + $PRIORITY{$prio} = $intval; >> + $LEVELS{$intval} = $prio; >> + $SYSLOG{$prio} = $syslog if defined($syslog); >> +} >> + >> +# create the basic priorities >> +add_priority("OFF", OFF_INT, -1); >> +add_priority("FATAL", FATAL_INT, 0); >> +add_priority("ERROR", ERROR_INT, 3); >> +add_priority("WARN", WARN_INT, 4); >> +add_priority("INFO", INFO_INT, 6); >> +add_priority("DEBUG", DEBUG_INT, 7); >> +add_priority("ALL", ALL_INT, 7); >> >> -our %PRIORITY = ( >> - "FATAL" => 0, >> - "ERROR" => 3, >> - "WARN" => 4, >> - "INFO" => 6, >> - "DEBUG" => 7, >> -) unless %PRIORITY; >> - >> - # Reverse mapping >> -our %LEVELS = map { $PRIORITY{$_} => $_ } keys %PRIORITY; >> - >> - # Min and max >> -$PRIORITY{'OFF'} = $PRIORITY{'FATAL'}; >> -$PRIORITY{'ALL'} = $PRIORITY{'DEBUG'}; >> +# we often sort numerically, so a helper func for readability >> +sub numerically {$a <=> $b} >> >> ########################################### >> sub import { >> @@ -43,6 +65,9 @@ >> my $name = "$namespace$key"; >> my $value = $PRIORITY{$key}; >> *{"$name"} = \$value; >> + my $nameint = "$namespace${key}_INT"; >> + my $func = uc($key) . "_INT"; >> + *{"$nameint"} = \&$func; >> } >> } >> >> @@ -75,8 +100,11 @@ >> if (exists $LEVELS{$priority}) { >> return $LEVELS{$priority} >> }else { >> - die "priority '$priority' is not a valid error level number >> (".join ('|', keys %LEVELS),')'; >> + die("priority '$priority' is not a valid error level number (", >> + join("|", sort numerically keys %LEVELS), " >> + )"); >> } >> + >> } >> >> ################################################## >> @@ -120,8 +148,9 @@ >> >> foreach (1..$delta){ >> #so the list is DEBUG, INFO, WARN, ERROR, FATAL >> - foreach my $p (reverse sort keys %LEVELS){ >> - if ($p < $old_priority) { >> + # but remember, the numbers go in reverse order! >> + foreach my $p (sort numerically keys %LEVELS){ >> + if ($p > $old_priority) { >> $new_priority = $p; >> last; >> } >> @@ -140,8 +169,9 @@ >> >> foreach (1..$delta){ >> #so the list is FATAL, ERROR, WARN, INFO, DEBUG >> - foreach my $p (sort keys %LEVELS){ >> - if ($p > $old_priority) { >> + # but remember, the numbers go in reverse order! >> + foreach my $p (reverse sort numerically keys %LEVELS){ >> + if ($p < $old_priority) { >> $new_priority = $p; >> last; >> } >> @@ -150,6 +180,25 @@ >> } >> return $new_priority; >> } >> + >> +sub isGreaterOrEqual { >> + my $lval = shift; >> + my $rval = shift; >> + + # in theory, we should check if the above really ARE valid levels. >> + # but we just use numeric comparison, since they aren't really >> classes. >> + >> + # oh, yeah, and 'cuz level ints go from 0 .. N with 0 being highest, >> + # these are reversed. >> + return $lval <= $rval; >> +} >> + >> +###################################################################### >> +# +# since the integer representation of levels is reversed from what >> +# we normally want, we don't want to use < and >... instead, we >> +# want to use this comparison function >> + >> >> 1; >> >> Index: lib/Log/Log4perl/Logger.pm >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Logger.pm,v >> retrieving revision 1.25 >> diff -a -u -r1.25 Logger.pm >> --- lib/Log/Log4perl/Logger.pm 3 Sep 2002 18:13:41 -0000 1.25 >> +++ lib/Log/Log4perl/Logger.pm 9 Sep 2002 02:11:20 -0000 >> @@ -139,8 +139,11 @@ >> >> my %priority = %Log::Log4perl::Level::PRIORITY; #convenience and cvs >> >> + # changed to >= from <= as level ints were reversed >> foreach my $levelname (keys %priority){ >> - if ($priority{$levelname} <= $level) { >> + if (Log::Log4perl::Level::isGreaterOrEqual($level, >> + $priority{$levelname} >> + )) { >> print " ($priority{$levelname} <= $level)\n" >> if DEBUG; >> $self->{$levelname} = $coderef; >> @@ -467,6 +470,8 @@ >> ################################################## >> my ($self, $priority, @messages) = @_; >> >> + confess("log: No priority given!") unless defined($priority); >> + >> # Just in case of 'init_and_watch' -- see Changes 0.21 >> $_[0] = $LOGGERS_BY_NAME->{$_[0]->{category}} if defined >> $LAST_CHECKED_AT; >> >> @@ -480,31 +485,111 @@ >> Log::Log4perl::Level::to_level($priority)); >> } >> >> +###################################################################### >> +# >> +# create_custom_level +# creates a custom level >> +# in theory, could be used to create the default ones >> >> -#now lets autogenerate the logger subs based on the defined priorities >> -foreach my $level (keys %Log::Log4perl::Level::PRIORITY){ >> +sub create_custom_level { >> + my $level = shift || die("create_custom_level: forgot to pass in a >> level string!"); >> + my $after = shift || die("create_custom_level: forgot to pass in an >> after string!"); >> + my $syslog_equiv = shift; # can be undef >> >> - my $lclevel = lc $level; >> - my $code = <<EOL; >> + ## only let users create custom levels before initialization >> >> - sub $lclevel { >> - print "$lclevel: (\$_[0]->{category}/\$_[0]->{level}) >> [\@_]\n" if DEBUG; >> - init_warn() unless \$INITIALIZED; >> - \$_[0]->{$level}(\@_, '$level'); >> - } >> - - sub is_$lclevel { return \$_[0]->level() >= \$$level; } >> -EOL >> + die("create_custom_level must be called before init or first >> get_logger() call") if ($INITIALIZED); >> >> - eval $code; >> + my %PRIORITY = %Log::Log4perl::Level::PRIORITY; #convenience >> >> - if ($@) { >> - die "Log4perl init failed, could not define a subroutine for >> $level:\n$code\n$@"; >> - } >> + die("create_custom_level: no such level \"$after\"! Use one of: ", >> join(", ", sort keys %PRIORITY)) >> + unless $PRIORITY{$after}; >> + >> + # figure out new int value by AFTER + (AFTER+ 1) / 2 >> + >> + my $next_prio = >> Log::Log4perl::Level::get_lower_level($PRIORITY{$after}, 1); >> + my $cust_prio = int(($PRIORITY{$after} + $next_prio) / 2); >> + >> +# CORE::warn("Creating prio $cust_prio between $PRIORITY{$after} >> and $next_prio"); >> + >> + die(qq{create_custom_level: Calculated level of $cust_prio already >> exists! >> + This should only happen if you've made some insane number of >> custom >> + levels (like 15 one after another) >> + You can usually fix this by re-arranging your code from: >> + create_custom_level("cust1", X); >> + create_custom_level("cust2", X); >> + create_custom_level("cust3", X); >> + create_custom_level("cust4", X); >> + create_custom_level("cust5", X); >> + into: >> + create_custom_level("cust3", X); >> + create_custom_level("cust5", X); >> + create_custom_level("cust4", 4); >> + create_custom_level("cust2", cust3); >> + create_custom_level("cust1", cust2); >> + }) if ($Log::Log4perl::Level::LEVELS{$cust_prio}); >> + >> + Log::Log4perl::Level::add_priority($level, $cust_prio, $syslog_equiv); >> + >> + print("Adding prio $level at $cust_prio\n") if DEBUG; >> + >> + # get $LEVEL into namespace of Log::Log4perl::Logger to + # create >> $logger->foo nd $logger->is_foo >> + my $name = "Log::Log4perl::Logger::"; >> + my $key = $level; >> + >> + no strict qw(refs); >> + # be sure to use ${Log...} as CVS adds log entries for Log >> + *{"$name$key"} = \${Log::Log4perl::Level::PRIORITY{$level}}; >> >> + # now, stick it in the caller's namespace >> + $name = caller(0) . "::"; >> + *{"$name$key"} = \${Log::Log4perl::Level::PRIORITY{$level}}; >> + use strict qw(refs); >> + >> + create_log_level_methods($level); >> + >> + return 0; >> >> } >> >> +######################################## >> +# >> +# if we were hackin' lisp (or scheme), we'd be returning some lambda >> +# expressions. But we aren't. :) So we'll just create some strings and >> +# eval them. >> +sub create_log_level_methods { >> + my $level = shift || die("create_log_level_methods: forgot to pass >> in a level string!"); >> + my $lclevel = lc($level); >> + my $levelint = uc($level) . "_INT"; >> + >> + no strict qw(refs); >> + >> + # This is a bit better way to create code on the fly than eval'ing >> strings. >> + # -erik >> + >> + *{__PACKAGE__ . "::$lclevel"} = sub { >> + print "$lclevel: ($_[0]->{category}/$_[0]->{level}) [@_]\n" >> if DEBUG; >> + init_warn() unless $INITIALIZED; >> + $_[0]->{$level}(@_, $level); >> + }; >> + >> + *{__PACKAGE__ . "::is_$lclevel"} = sub { + return >> Log::Log4perl::Level::isGreaterOrEqual($_[0]->level(), >> + $$level); + }; >> + + use strict qw(refs); >> + >> + return 0; >> + >> +} >> + >> +#now lets autogenerate the logger subs based on the defined priorities >> +foreach my $level (keys %Log::Log4perl::Level::PRIORITY){ >> + create_log_level_methods($level); >> +} >> + >> ################################################## >> #expected args are $logger, $msg, $levelname >> >> @@ -602,8 +687,9 @@ >> my $self = shift; >> if ($self->is_fatal()) { >> $self->fatal(@_); >> - $self->and_die(@_); >> } >> + # no matter what, we die... 'cuz logdie wants you to die. >> + $self->and_die(@_); >> } >> >> ################################################## >> @@ -641,24 +727,26 @@ >> # croaks and confess are FATAL level >> sub logcroak { >> my $self = shift; >> + my $message = Carp::shortmess(@_); >> if ($self->is_fatal()) { >> - my $message = Carp::shortmess(@_); >> foreach (split(/\n/, $message)) { >> $self->fatal("$_\n"); >> } >> - die(noop($message)); >> } >> + # again, we die no matter what >> + die(noop($message)); >> } >> >> sub logconfess { >> my $self = shift; >> + my $message = Carp::longmess(@_); >> if ($self->is_fatal()) { >> - my $message = Carp::longmess(@_); >> foreach (split(/\n/, $message)) { >> $self->fatal("$_\n"); >> } >> - die(noop($message)); >> } >> + # again, we die no matter what >> + die(noop($message)); >> } >> >> ################################################## >> @@ -677,8 +765,8 @@ >> my $self = shift; >> if ($self->is_error()) { >> $self->error(@_); >> - $self->and_die(@_); >> } >> + $self->and_die(@_); >> } >> >> sub inc_level { >> Index: t/001Level.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/001Level.t,v >> retrieving revision 1.1.1.1 >> diff -a -u -r1.1.1.1 001Level.t >> --- t/001Level.t 3 Jul 2002 21:53:33 -0000 1.1.1.1 >> +++ t/001Level.t 9 Sep 2002 02:11:20 -0000 >> @@ -7,7 +7,9 @@ >> # change 'tests => 1' to 'tests => last_test_to_print'; >> ######################### >> use Test; >> -BEGIN { plan tests => 10 }; >> +use strict; >> + >> +BEGIN { plan tests => 20 }; >> use Log::Log4perl::Level; >> BEGIN { >> Log::Log4perl::Level->import("Level"); >> @@ -16,16 +18,23 @@ >> ok(1); # If we made it this far, we're ok. >> >> # Import them into the 'main' namespace; >> -ok($FATAL < $ERROR); >> -ok($ERROR < $INFO); >> -ok($INFO < $DEBUG); >> +foreach ($DEBUG, $INFO, $WARN, $ERROR, $FATAL) { >> + ok(Log::Log4perl::Level::to_level($_)); >> +} >> # Import them into the 'Level' namespace; >> -ok($Level::FATAL < $Level::ERROR); >> -ok($Level::ERROR < $Level::INFO); >> -ok($Level::INFO < $Level::DEBUG); >> +foreach ($Level::DEBUG, $Level::INFO, $Level::WARN, $Level::ERROR, >> $Level::FATAL) { >> + ok(Log::Log4perl::Level::to_level($_)); >> +} >> >> # Import them into the 'My::Level' namespace; >> -ok($My::Level::FATAL < $My::Level::ERROR); >> -ok($My::Level::ERROR < $My::Level::INFO); >> -ok($My::Level::INFO < $My::Level::DEBUG); >> +foreach ($My::Level::DEBUG, $My::Level::INFO, $My::Level::WARN, >> $My::Level::ERROR, $My::Level::FATAL) { >> + ok(Log::Log4perl::Level::to_level($_)); >> +} >> + >> +# ok, now let's check to make sure the relative order is correct. >> + >> +ok(Log::Log4perl::Level::isGreaterOrEqual($DEBUG, $INFO)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($INFO, $WARN)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($WARN, $ERROR)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($ERROR, $FATAL)); >> Index: t/002Logger.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/002Logger.t,v >> retrieving revision 1.14 >> diff -a -u -r1.14 002Logger.t >> --- t/002Logger.t 6 Aug 2002 19:36:25 -0000 1.14 >> +++ t/002Logger.t 9 Sep 2002 02:11:20 -0000 >> @@ -9,10 +9,18 @@ >> use strict; >> >> ######################### >> -# change 'tests => 1' to 'tests => last_test_to_print'; >> -######################### >> -use Test; >> +# used Test::Simple to help debug the test script >> +use Test::Simple tests => 46; >> >> +# to test, as ok() suppresses DEBUG output >> +# my $i = 1; >> +# sub ok { >> +# my ($r, $s) = @_; >> +# print "not " unless ($r); >> +# print "ok ", $i++; >> +# print " - $s" if (defined($s)); >> +# print "\n"; >> +# } >> use Log::Log4perl; >> use Log::Log4perl::Level; >> @@ -30,22 +38,22 @@ >> my $log9 = Log::Log4perl->get_logger("abc::def::ghi"); >> >> # Loggers for the same namespace have to be identical >> -ok($log1 == $log2); >> -ok($log4 == $log5); >> -ok($log6 == $log7); >> -ok($log1 == $log8); >> -ok($log3 == $log9); >> +ok($log1 == $log2, "Log1 same as Log2"); >> +ok($log4 == $log5, "Log4 same as Log5"); >> +ok($log6 == $log7, "Log6 same as Log7"); >> +ok($log1 == $log8, "Log1 same as Log8"); >> +ok($log3 == $log9, "log3 same as Log9"); >> >> # Loggers for different namespaces have to be different >> -ok($log1 != $log3); >> -ok($log3 != $log4); >> -ok($log1 != $log6); >> -ok($log3 != $log6); >> -ok($log5 != $log6); >> -ok($log5 != $log7); >> -ok($log5 != $log1); >> -ok($log7 != $log8); >> -ok($log8 != $log9); >> +ok($log1 != $log3, "Log1 not Log3"); >> +ok($log3 != $log4, "Log3 not Log4"); >> +ok($log1 != $log6, "Log1 not Log6"); >> +ok($log3 != $log6, "Log3 not Log6"); >> +ok($log5 != $log6, "Log5 not Log6"); >> +ok($log5 != $log7, "Log5 not Log7"); >> +ok($log5 != $log1, "Log5 not Log1"); >> +ok($log7 != $log8, "Log7 not Log8"); >> +ok($log8 != $log9, "Log8 not Log9"); >> >> my $app = Log::Log4perl::Appender->new( >> "Log::Log4perl::TestBuffer"); >> @@ -55,10 +63,14 @@ >> ################################################## >> $log1->add_appender($app); >> $log1->level($ERROR); >> + >> +# warn "level is: ", $log1->level(), "\n"; >> + >> $log1->error("Error Message"); >> $log1->debug("Debug Message"); >> -ok($app->buffer(), "ERROR - Error Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\n", "log1 app buffer >> contains ERROR - Error Message"); >> >> +# warn "app buffer is: \"", $app->buffer(), "\"\n"; >> >> ################################################## >> # Allow debug >> @@ -67,7 +79,10 @@ >> $app->buffer(""); >> $log1->error("Error Message"); >> $log1->debug("Debug Message"); >> -ok($app->buffer(), "ERROR - Error Message\nDEBUG - Debug Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\nDEBUG - Debug Message\n", >> + "app buffer contains both ERROR and DEBUG message"); >> + >> +# warn "app buffer is: \"", $app->buffer(), "\"\n"; >> >> ################################################## >> # Multiple Appenders >> @@ -84,8 +99,8 @@ >> $log1->level($ERROR); >> $log1->error("Error Message"); >> #TODO >> -ok($app->buffer(), "ERROR - Error Message\n"); >> -ok($app2->buffer(), "ERROR - Error Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\n", "app buffer contains >> ERROR only"); >> +ok($app2->buffer() eq "ERROR - Error Message\n", "app2 buffer >> contains ERROR only"); >> >> ################################################## >> # Multiple Appenders in different hierarchy levels >> @@ -109,7 +124,7 @@ >> $log1->error("Error Message"); >> >> # Should be distributed to root >> -ok($app3->buffer(), "ERROR - Error Message\n"); >> +ok($app3->buffer() eq "ERROR - Error Message\n", "app3 buffer >> contains ERROR"); >> ################################################## >> # Log in lower levels and propagate to root >> ################################################## >> @@ -121,9 +136,9 @@ >> $log2->add_appender($app2); >> # log3 already has app3 attached >> $log1->error("Error Message"); >> -ok($app->buffer(), "ERROR - Error Message\n"); >> -ok($app2->buffer(), "ERROR - Error Message\n"); >> -ok($app3->buffer(), "ERROR - Error Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\n", "app buffer contains >> ERROR"); >> +ok($app2->buffer() eq "ERROR - Error Message\n", "app2 buffer >> contains ERROR"); >> +ok($app3->buffer() eq "ERROR - Error Message\n", "app3 buffer >> contains ERROR"); >> >> ################################################## >> # Block appenders via priority @@ -137,9 +152,9 @@ >> $log3->level($DEBUG); >> >> $log1->debug("Debug Message"); >> -ok($app->buffer(), ""); >> -ok($app2->buffer(), ""); >> -ok($app3->buffer(), ""); >> +ok($app->buffer() eq "", "app buffer is empty"); >> +ok($app2->buffer() eq "", "app2 buffer is empty"); >> +ok($app3->buffer() eq "", "app3 buffer is empty"); >> >> ################################################## >> # Block via 'false' additivity >> @@ -154,9 +169,9 @@ >> $log3->level($DEBUG); >> >> $log1->debug("Debug Message"); >> -ok($app->buffer(), "DEBUG - Debug Message\n"); >> -ok($app2->buffer(), "DEBUG - Debug Message\n"); >> -ok($app3->buffer(), ""); >> +ok($app->buffer() eq "DEBUG - Debug Message\n", "app buffer contains >> DEBUG"); >> +ok($app2->buffer() eq "DEBUG - Debug Message\n", "app2 buffer >> contains DEBUG"); >> +ok($app3->buffer() eq "", "app3 buffer is empty"); >> >> ################################################## >> # Check is_*() functions >> @@ -165,20 +180,20 @@ >> $log2->level($ERROR); >> $log3->level($INFO); >> >> -ok($log1->is_error(), 1); >> -ok($log1->is_info(), 1); >> -ok($log1->is_fatal(), 1); >> -ok($log1->is_debug(), 1); >> - >> -ok($log2->is_error(), 1); >> -ok($log2->is_info(), ""); >> -ok($log2->is_fatal(), 1); >> -ok($log2->is_debug(), ""); >> - >> -ok($log3->is_error(), 1); >> -ok($log3->is_info(), 1); >> -ok($log3->is_fatal(), 1); >> -ok($log3->is_debug(), ""); >> +ok($log1->is_error(), "log1 is_error == 1"); >> +ok($log1->is_info(), "log1 is_info == 1"); >> +ok($log1->is_fatal(), "log1 is_fatal == 1"); >> +ok($log1->is_debug(), "log1 is_debug == 1"); >> + >> +ok($log2->is_error(), "log2 is_error == 1"); >> +ok(!$log2->is_info(), "log2 is_info == 0"); >> +ok($log2->is_fatal(), "log2 is_fatal == 1"); >> +ok(!$log2->is_debug(), "log2 is_debug == 0"); >> + >> +ok($log3->is_error(), "log3 is_error == 1"); >> +ok($log3->is_info(), "log3 is_info == 1"); >> +ok($log3->is_fatal(), "log3 is_fatal == 1"); >> +ok(!$log3->is_debug(), "log3 is_debug == 0"); >> >> >> ################################################## >> @@ -201,9 +216,12 @@ >> $log3->log($DEBUG, "debug message"); >> $log3->log($INFO, "info message "); >> >> -ok($app->buffer(), "DEBUG - debug message\nINFO - info message \n"); >> -ok($app2->buffer(),"DEBUG - debug message\nINFO - info message \n"); >> -ok($app3->buffer(),"INFO - info message \n"); >> +ok($app->buffer() eq "DEBUG - debug message\nINFO - info message \n", >> + "app buffer contains DEBUG and INFO"); >> +ok($app2->buffer() eq "DEBUG - debug message\nINFO - info message \n", >> + "app2 buffer contains DEBUG"); >> +ok($app3->buffer() eq "INFO - info message \n", >> + "app3 buffer contains INFO"); >> >> ################################################## >> # Check several messages concatenated >> @@ -219,7 +237,7 @@ >> $log1->error("9 ", "10 "); >> $log1->fatal("11 ", "12 ", "13 "); >> >> -ok($app->buffer(), <<EOT); >> +ok($app->buffer() eq <<EOT, "app buffer six lines"); >> DEBUG - 1 2 DEBUG - 3 4 INFO - 5 6 @@ -238,9 +256,11 @@ >> $log1->log($DEBUG, sub { "1" . " " . "2" } ); >> $log1->info(sub { "3 " . "4 " }, sub { "5 " . "6 " }); >> >> -ok($app->buffer(), <<EOT); >> +ok($app->buffer() eq <<EOT, "app buffer contains 2 lines"); >> DEBUG - 1 2 >> INFO - 3 4 5 6 EOT >> >> -BEGIN { plan tests => 46 }; >> +# warn("app buffer is: ", $app->buffer(), "\n"); >> + >> +# BEGIN { plan tests => 46 }; >> Index: t/016Export.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/016Export.t,v >> retrieving revision 1.5 >> diff -a -u -r1.5 016Export.t >> --- t/016Export.t 4 Aug 2002 20:01:40 -0000 1.5 >> +++ t/016Export.t 9 Sep 2002 02:11:24 -0000 >> @@ -18,10 +18,10 @@ >> >> ok(1); >> >> -ok($DEBUG > $ERROR); >> -ok($INFO > $WARN); >> -ok($WARN > $ERROR); >> -ok($ERROR > $FATAL); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($DEBUG, $ERROR)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($INFO, $WARN)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($WARN, $ERROR)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($ERROR, $FATAL)); >> >> ################################################## >> # Init logger >> Index: t/024WarnDieCarp.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/024WarnDieCarp.t,v >> retrieving revision 1.1 >> diff -a -u -r1.1 024WarnDieCarp.t >> --- t/024WarnDieCarp.t 29 Aug 2002 05:33:28 -0000 1.1 >> +++ t/024WarnDieCarp.t 9 Sep 2002 02:11:25 -0000 >> @@ -46,6 +46,17 @@ >> ok($app->buffer() !~ /$out_str/, "$mname($in_str): Buffer does NOT >> contain \"$out_str\""); >> } >> >> +# same as above, just look for no output in buffer, but output in STDERR >> +sub dietest_nooutput { >> + my ($method, $in_str, $out_str, $app, $mname) = @_; >> + >> + eval { &$method($in_str) }; >> + + ok($warnstr =~ /$out_str/, "$mname($in_str): STDERR contains >> \"$out_str\""); >> + ok($app->buffer() !~ /$out_str/, "$mname($in_str): Buffer does NOT >> contain \"$out_str\""); >> +} >> + >> + >> ok(1, "Initialized OK"); >> ############################################################ >> @@ -94,13 +105,12 @@ >> >> $log->level($OFF); # $OFF == $FATAL... although I suspect that's a bug >> in the log4j spec >> >> -foreach my $f ("logwarn", "logcarp", "logcluck", >> - "error_warn", "error_die") { >> +foreach my $f ("logwarn", "logcarp", "logcluck", "error_warn") { >> warndietest_nooutput(sub {$log->$f(@_)}, "Test $test: $f", "Test >> $test: $f", $app, "$f"); >> $test++; >> } >> >> -foreach my $f ("logdie", "logcroak", "logconfess") { >> - warndietest(sub {$log->$f(@_)}, "Test $test: $f", "Test $test: $f", >> $app, "$f"); >> +foreach my $f ("error_die", "logdie", "logcroak", "logconfess") { >> + dietest_nooutput(sub {$log->$f(@_)}, "Test $test: $f", "Test $test: >> $f", $app, "$f"); >> $test++; >> } >> Index: t/025CustLevels.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/025CustLevels.t,v >> retrieving revision 1.1 >> diff -a -u -r1.1 025CustLevels.t >> --- t/025CustLevels.t 3 Sep 2002 18:09:42 -0000 1.1 >> +++ t/025CustLevels.t 9 Sep 2002 02:11:26 -0000 >> @@ -1,6 +1,7 @@ >> ########################################### >> # Test Suite for Log::Log4perl::Config >> -# Mike Schilli, 2002 (m...@pe...) >> +# Erik Selberg, (c) 2002 er...@se... >> +# clone of 025CustLevels.t but uses nicer method (?) we hope >> ########################################### >> >> ######################### >> @@ -9,26 +10,61 @@ >> use Test; >> >> #create a custom level "LITEWARN" >> -BEGIN { >> -package Log::Log4perl::Level; >> -our %PRIORITY = ( >> - "FATAL" => 0, >> - "ERROR" => 3, >> - "WARN" => 4, >> - "LITEWARN" => 5, >> - "INFO" => 6, >> - "DEBUG" => 7, >> -); >> -} >> - >> - >> use Log::Log4perl; >> use Log::Log4perl::Level; >> use Log::Log4perl::TestBuffer; >> +# use strict; >> >> >> ok(1); # If we made it this far, we're ok. >> >> +Log::Log4perl::Logger::create_custom_level("LITEWARN", "WARN"); >> + >> +# test insane creation of levels >> + >> +foreach (1 .. 14) { >> + ok(Log::Log4perl::Logger::create_custom_level("TEST$_", "INFO"), 0); >> +} >> + >> +# 15th should fail.. this assumes that each level is 10000 apart from >> +# the other. >> + >> +ok(eval { Log::Log4perl::Logger::create_custom_level("TEST15", >> "INFO") }, + undef); >> + >> +# now, by re-arranging (as we whine about in create_custom_levels), we >> +# should be able to get 15. >> + >> +my %btree = ( >> + 8 => "DEBUG", >> + 4 => 8, >> + 2 => 4, >> + 1 => 2, >> + 3 => 4, >> + 6 => 8, >> + 5 => 6, >> + 7 => 8, >> + 12 => "DEBUG", >> + 10 => 12, >> + 9 => 10, >> + 11 => 12, >> + 14 => "DEBUG", >> + 13 => 14, >> + 15 => "DEBUG", >> + ); >> + >> +foreach (8, 4, 2, 1, 3, 6, 5, 7, 12, 10, 9, 11, 14, 13, 15) { >> + my $level = $btree{$_} eq "DEBUG" ? "DEBUG" : "BTREE$btree{$_}"; >> +# warn("Creating BTREE$_ after $level"); >> + ok(Log::Log4perl::Logger::create_custom_level("BTREE$_", $level), 0); >> +# warn("BTREE$_ is ", ${Log::Log4perl::Level::PRIORITY{"BTREE$_"}}); >> +} >> + >> +# foreach (1 .. 15) { >> +# warn("BTREE$_ is: ", ${Log::Log4perl::Level::PRIORITY{"BTREE$_"}}); >> +# } >> + >> + >> my $LOGFILE = "example.log"; >> unlink $LOGFILE; >> >> @@ -40,10 +76,16 @@ >> EOT >> >> >> - >> Log::Log4perl::init(\$config); >> >> >> +# can't create a custom level after init... let's test that. Just look >> +# for an undef (i.e. failure) from the eval >> + >> +ok(eval { Log::Log4perl::Logger::create_custom_level("NOTIFY", >> "WARN"); }, >> + undef); >> + >> + >> # ********************* >> # check a category logger >> >> @@ -76,6 +118,7 @@ >> >> $logger->log($WARN, "a warning message"); >> $logger->log($LITEWARN, "a LITE warning message"); >> +die("lame hack to suppress warning") if ($LITEWARN != $LITEWARN); >> $logger->log($DEBUG, "an info message, should not log"); >> >> open FILE, "<$LOGFILE" or die "Cannot open $LOGFILE"; >> @@ -92,9 +135,12 @@ >> ok(! $logger->is_info); >> >> >> +# warn("Testing inc_level()"); >> + >> #*************************** >> #increase/decrease leves >> -$logger->inc_level(); #bump up from litewarn to warn >> +$logger->inc_level(1); #bump up from litewarn to warn >> +# warn("level is now: ", $logger->level()); >> ok($logger->is_warn); >> ok(!$logger->is_litewarn); >> ok(!$logger->is_info); >> @@ -107,14 +153,15 @@ >> my $result4 = "WARN - after bumping, warning message\n"; >> ok($data, "$result1$result2$result3$result4"); >> >> - >> $logger->dec_level(2); #bump down from warn to litewarn to info >> + >> ok($logger->is_warn); >> ok($logger->is_litewarn); >> ok($logger->is_info); >> + >> ok(! $logger->is_debug) ; >> >> >> -BEGIN { plan tests => 15 }; >> +BEGIN { plan tests => 46 }; >> >> unlink $LOGFILE; >> >> > > > -- Happy Trails . . . Kevin M. Goess (and Anne and Frank) 904 Carmel Ave. Albany, CA 94706 (510) 525-5217 |
From: Kevin G. <ke...@go...> - 2002-09-09 17:51:58
|
Mike/Erik: I just found a heinous bug in the watch code, if the logger was called *more* often than the wait interval than the config would never be reloaded. A patch is attached, with a change in the test case to verify the original behavior. But I begin to doubt my sanity, I don't suppose one of you has a minute to look at Logger::generate_watch_code after the patch and see if the timing makes sense? -- Happy Trails . . . Kevin M. Goess (and Anne and Frank) 904 Carmel Ave. Albany, CA 94706 (510) 525-5217 |
From: Erik S. <er...@se...> - 2002-09-09 08:46:56
|
Ok, created a new patch: http://speedstation.whizzyfoo.com/Log-Log4perl/custlevel4.patch - Adds a better die() statement - Adds some documentation on custom_log_level - Adds some documentation on more/less_logging and inc/dec_level - Makes more_logging / less_logging synonyms for inc_level / dec_level - Adds Test::Simple to Makefile.PL (didn't realize it wasn't there already; Test::Simple isn't part of Perl 5.00x, although it is in 5.6.1, but since we're 5.000x compat, we should include it as a requirement). -e msc...@ao... wrote: >>Maybe Mozilla is doing weird stuff... anyway, I >>re-confirmed that the patch works. But to make life >>easy, I put it up on my website. >> >> > >Interesting. Can you confirm the patch works even after you send mail to yourself? > >Anyway, the patch on your website worked (yay!) like a charm. Couple of questions/requests on your changes: > >* Looks like the error message here got garbeled (Logger.pm): > > my $after = shift || die("create_custom_level: forgot to pass in an after string! > >* What's the purpose of > > our %PRIORITY = (); # unless (%PRIORITY); > our %LEVELS = () unless (%LEVELS); > our %SYSLOG = () unless (%SYSLOG); > >And why the '#' in the first line? > >* Documentation: Can you add a couple of lines to Log::Log4perl.pm to show how to use the custom level features? > >* Why the logic > > # figure out new int value by AFTER + (AFTER+ 1) / 2 > >if you could just store the priorities defined so far orderly in an array and switch to the next/previous element? > >* # This is a bit better way to create code on the fly than eval'ing strings. > # -erik > >Nice. Does this mean they're (-d) debuggable now? Could we go all the way and use this in set_output_methods() as well? > >Looks like your foreach loop is outside the subroutine and therefore only called when the module is loaded: > > #now lets autogenerate the logger subs based on the defined priorities > foreach my $level (keys %Log::Log4perl::Level::PRIORITY){ > create_log_level_methods($level); >} > >Would be great if you could shed some light on these >issues ... :) > >-- Mike > >Mike Schilli >log...@pe... >http://perlmeister.com > > > > ------------------------------------------------------------------------ > > Subject: > Re: Release 0.23 because of upcoming article? > From: > er...@se... > Date: > Sun, 08 Sep 2002 20:50:42 -0700 > To: > "Erik W. Selberg" <er...@se...> > > > > Maybe Mozilla is doing weird stuff... anyway, I re-confirmed that the > patch works. But to make life easy, I put it up on my website. > > http://speedstation.whizzyfoo.com/Log-Log4perl/custlevel3.patch > > Note: Log4perl.patchable is just a copy of a fresh checkout. > > 121 speedstation:Log-Log4perl.patchable >patch -p0 < ../custlevel3.patch > patching file lib/Log/Log4perl/Appender.pm > patching file lib/Log/Log4perl/Level.pm > patching file lib/Log/Log4perl/Logger.pm > patching file t/001Level.t > patching file t/002Logger.t > patching file t/016Export.t > patching file t/024WarnDieCarp.t > patching file t/025CustLevels.t > 122 speedstation:Log-Log4perl.patchable > > > -e > > Erik W. Selberg wrote: > >> Hmm.... that's what I did. >> >> Well, here goes again. Can ya let me know what the output of patch is >> if it doesn't go through? >> >> Thanks, >> -e >> >> msc...@ao... wrote: >> >>> In a message dated Sun, 8 Sep 2002 4:31:30 AM Eastern Standard Time, >>> er...@se... writes: >>> >>> >>> >>>> Please apply the patch.. >>>> >>> >>> >>> >>> Ok ... just tried to apply your latest patch, unfortunately it >>> doesn't go through -- maybe it's my email client mangling the lines, >>> so please >>> >>> 1) use "cvs diff -Nau" of your local dir against CVS >>> 2) send the patch as an attachment >>> >>> Thanks! >>> >>> -- Mike >>> >>> Mike Schilli >>> log...@pe... >>> http://perlmeister.com >>> >>> >>> >> >> >> ------------------------------------------------------------------------ >> >> ? out.txt >> Index: lib/Log/Log4perl/Appender.pm >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Appender.pm,v >> retrieving revision 1.8 >> diff -a -u -r1.8 Appender.pm >> --- lib/Log/Log4perl/Appender.pm 21 Aug 2002 07:52:51 -0000 1.8 >> +++ lib/Log/Log4perl/Appender.pm 9 Sep 2002 02:11:14 -0000 >> @@ -83,8 +83,9 @@ >> >> # Check if the appender has a last-minute veto in form >> # of an "appender threshold" >> - if($self->{level} < $ >> + if($self->{level} > $ >> Log::Log4perl::Level::PRIORITY{$level}) { >> + print "$self->{level} > $level, aborting\n" if DEBUG; >> return; >> } >> >> Index: lib/Log/Log4perl/Level.pm >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Level.pm,v >> retrieving revision 1.6 >> diff -a -u -r1.6 Level.pm >> --- lib/Log/Log4perl/Level.pm 3 Sep 2002 18:12:17 -0000 1.6 >> +++ lib/Log/Log4perl/Level.pm 9 Sep 2002 02:11:16 -0000 >> @@ -7,22 +7,44 @@ >> use warnings; >> use Carp; >> >> +# log4j, for whatever reason, puts 0 as all and MAXINT as OFF. >> +# this seems less optimal, as more logging would imply a higher >> +# level. But oh well. Probably some brokenness that has persisted. :) >> +use constant ALL_INT => 0; >> +use constant DEBUG_INT => 10000; >> +use constant INFO_INT => 20000; >> +use constant WARN_INT => 30000; >> +use constant ERROR_INT => 40000; >> +use constant FATAL_INT => 50000; >> +use constant OFF_INT => (2 ** 31) - 1; >> + >> no strict qw(refs); >> +use vars qw(%PRIORITY %LEVELS); >> + >> +our %PRIORITY = (); # unless (%PRIORITY); >> +our %LEVELS = () unless (%LEVELS); >> +our %SYSLOG = () unless (%SYSLOG); >> + >> +sub add_priority { >> + my ($prio, $intval, $syslog) = @_; >> + $prio = uc($prio); # just in case; >> + >> + $PRIORITY{$prio} = $intval; >> + $LEVELS{$intval} = $prio; >> + $SYSLOG{$prio} = $syslog if defined($syslog); >> +} >> + >> +# create the basic priorities >> +add_priority("OFF", OFF_INT, -1); >> +add_priority("FATAL", FATAL_INT, 0); >> +add_priority("ERROR", ERROR_INT, 3); >> +add_priority("WARN", WARN_INT, 4); >> +add_priority("INFO", INFO_INT, 6); >> +add_priority("DEBUG", DEBUG_INT, 7); >> +add_priority("ALL", ALL_INT, 7); >> >> -our %PRIORITY = ( >> - "FATAL" => 0, >> - "ERROR" => 3, >> - "WARN" => 4, >> - "INFO" => 6, >> - "DEBUG" => 7, >> -) unless %PRIORITY; >> - >> - # Reverse mapping >> -our %LEVELS = map { $PRIORITY{$_} => $_ } keys %PRIORITY; >> - >> - # Min and max >> -$PRIORITY{'OFF'} = $PRIORITY{'FATAL'}; >> -$PRIORITY{'ALL'} = $PRIORITY{'DEBUG'}; >> +# we often sort numerically, so a helper func for readability >> +sub numerically {$a <=> $b} >> >> ########################################### >> sub import { >> @@ -43,6 +65,9 @@ >> my $name = "$namespace$key"; >> my $value = $PRIORITY{$key}; >> *{"$name"} = \$value; >> + my $nameint = "$namespace${key}_INT"; >> + my $func = uc($key) . "_INT"; >> + *{"$nameint"} = \&$func; >> } >> } >> >> @@ -75,8 +100,11 @@ >> if (exists $LEVELS{$priority}) { >> return $LEVELS{$priority} >> }else { >> - die "priority '$priority' is not a valid error level number >> (".join ('|', keys %LEVELS),')'; >> + die("priority '$priority' is not a valid error level number (", >> + join("|", sort numerically keys %LEVELS), " >> + )"); >> } >> + >> } >> >> ################################################## >> @@ -120,8 +148,9 @@ >> >> foreach (1..$delta){ >> #so the list is DEBUG, INFO, WARN, ERROR, FATAL >> - foreach my $p (reverse sort keys %LEVELS){ >> - if ($p < $old_priority) { >> + # but remember, the numbers go in reverse order! >> + foreach my $p (sort numerically keys %LEVELS){ >> + if ($p > $old_priority) { >> $new_priority = $p; >> last; >> } >> @@ -140,8 +169,9 @@ >> >> foreach (1..$delta){ >> #so the list is FATAL, ERROR, WARN, INFO, DEBUG >> - foreach my $p (sort keys %LEVELS){ >> - if ($p > $old_priority) { >> + # but remember, the numbers go in reverse order! >> + foreach my $p (reverse sort numerically keys %LEVELS){ >> + if ($p < $old_priority) { >> $new_priority = $p; >> last; >> } >> @@ -150,6 +180,25 @@ >> } >> return $new_priority; >> } >> + >> +sub isGreaterOrEqual { >> + my $lval = shift; >> + my $rval = shift; >> + + # in theory, we should check if the above really ARE valid levels. >> + # but we just use numeric comparison, since they aren't really >> classes. >> + >> + # oh, yeah, and 'cuz level ints go from 0 .. N with 0 being highest, >> + # these are reversed. >> + return $lval <= $rval; >> +} >> + >> +###################################################################### >> +# +# since the integer representation of levels is reversed from what >> +# we normally want, we don't want to use < and >... instead, we >> +# want to use this comparison function >> + >> >> 1; >> >> Index: lib/Log/Log4perl/Logger.pm >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Logger.pm,v >> retrieving revision 1.25 >> diff -a -u -r1.25 Logger.pm >> --- lib/Log/Log4perl/Logger.pm 3 Sep 2002 18:13:41 -0000 1.25 >> +++ lib/Log/Log4perl/Logger.pm 9 Sep 2002 02:11:20 -0000 >> @@ -139,8 +139,11 @@ >> >> my %priority = %Log::Log4perl::Level::PRIORITY; #convenience and cvs >> >> + # changed to >= from <= as level ints were reversed >> foreach my $levelname (keys %priority){ >> - if ($priority{$levelname} <= $level) { >> + if (Log::Log4perl::Level::isGreaterOrEqual($level, >> + $priority{$levelname} >> + )) { >> print " ($priority{$levelname} <= $level)\n" >> if DEBUG; >> $self->{$levelname} = $coderef; >> @@ -467,6 +470,8 @@ >> ################################################## >> my ($self, $priority, @messages) = @_; >> >> + confess("log: No priority given!") unless defined($priority); >> + >> # Just in case of 'init_and_watch' -- see Changes 0.21 >> $_[0] = $LOGGERS_BY_NAME->{$_[0]->{category}} if defined >> $LAST_CHECKED_AT; >> >> @@ -480,31 +485,111 @@ >> Log::Log4perl::Level::to_level($priority)); >> } >> >> +###################################################################### >> +# >> +# create_custom_level +# creates a custom level >> +# in theory, could be used to create the default ones >> >> -#now lets autogenerate the logger subs based on the defined priorities >> -foreach my $level (keys %Log::Log4perl::Level::PRIORITY){ >> +sub create_custom_level { >> + my $level = shift || die("create_custom_level: forgot to pass in a >> level string!"); >> + my $after = shift || die("create_custom_level: forgot to pass in >> an after string!"); >> + my $syslog_equiv = shift; # can be undef >> >> - my $lclevel = lc $level; >> - my $code = <<EOL; >> + ## only let users create custom levels before initialization >> >> - sub $lclevel { >> - print "$lclevel: (\$_[0]->{category}/\$_[0]->{level}) >> [\@_]\n" if DEBUG; >> - init_warn() unless \$INITIALIZED; >> - \$_[0]->{$level}(\@_, '$level'); >> - } >> - - sub is_$lclevel { return \$_[0]->level() >= \$$level; } >> -EOL >> + die("create_custom_level must be called before init or first >> get_logger() call") if ($INITIALIZED); >> >> - eval $code; >> + my %PRIORITY = %Log::Log4perl::Level::PRIORITY; #convenience >> >> - if ($@) { >> - die "Log4perl init failed, could not define a subroutine for >> $level:\n$code\n$@"; >> - } >> + die("create_custom_level: no such level \"$after\"! Use one of: ", >> join(", ", sort keys %PRIORITY)) >> + unless $PRIORITY{$after}; >> + >> + # figure out new int value by AFTER + (AFTER+ 1) / 2 >> + >> + my $next_prio = >> Log::Log4perl::Level::get_lower_level($PRIORITY{$after}, 1); >> + my $cust_prio = int(($PRIORITY{$after} + $next_prio) / 2); >> + >> +# CORE::warn("Creating prio $cust_prio between $PRIORITY{$after} >> and $next_prio"); >> + >> + die(qq{create_custom_level: Calculated level of $cust_prio already >> exists! >> + This should only happen if you've made some insane number of >> custom >> + levels (like 15 one after another) >> + You can usually fix this by re-arranging your code from: >> + create_custom_level("cust1", X); >> + create_custom_level("cust2", X); >> + create_custom_level("cust3", X); >> + create_custom_level("cust4", X); >> + create_custom_level("cust5", X); >> + into: >> + create_custom_level("cust3", X); >> + create_custom_level("cust5", X); >> + create_custom_level("cust4", 4); >> + create_custom_level("cust2", cust3); >> + create_custom_level("cust1", cust2); >> + }) if ($Log::Log4perl::Level::LEVELS{$cust_prio}); >> + >> + Log::Log4perl::Level::add_priority($level, $cust_prio, >> $syslog_equiv); >> + >> + print("Adding prio $level at $cust_prio\n") if DEBUG; >> + >> + # get $LEVEL into namespace of Log::Log4perl::Logger to + # >> create $logger->foo nd $logger->is_foo >> + my $name = "Log::Log4perl::Logger::"; >> + my $key = $level; >> + >> + no strict qw(refs); >> + # be sure to use ${Log...} as CVS adds log entries for Log >> + *{"$name$key"} = \${Log::Log4perl::Level::PRIORITY{$level}}; >> >> + # now, stick it in the caller's namespace >> + $name = caller(0) . "::"; >> + *{"$name$key"} = \${Log::Log4perl::Level::PRIORITY{$level}}; >> + use strict qw(refs); >> + >> + create_log_level_methods($level); >> + >> + return 0; >> >> } >> >> +######################################## >> +# >> +# if we were hackin' lisp (or scheme), we'd be returning some lambda >> +# expressions. But we aren't. :) So we'll just create some strings and >> +# eval them. >> +sub create_log_level_methods { >> + my $level = shift || die("create_log_level_methods: forgot to pass >> in a level string!"); >> + my $lclevel = lc($level); >> + my $levelint = uc($level) . "_INT"; >> + >> + no strict qw(refs); >> + >> + # This is a bit better way to create code on the fly than eval'ing >> strings. >> + # -erik >> + >> + *{__PACKAGE__ . "::$lclevel"} = sub { >> + print "$lclevel: ($_[0]->{category}/$_[0]->{level}) [@_]\n" >> if DEBUG; >> + init_warn() unless $INITIALIZED; >> + $_[0]->{$level}(@_, $level); >> + }; >> + >> + *{__PACKAGE__ . "::is_$lclevel"} = sub { + return >> Log::Log4perl::Level::isGreaterOrEqual($_[0]->level(), >> + $$level); + }; >> + + use strict qw(refs); >> + >> + return 0; >> + >> +} >> + >> +#now lets autogenerate the logger subs based on the defined priorities >> +foreach my $level (keys %Log::Log4perl::Level::PRIORITY){ >> + create_log_level_methods($level); >> +} >> + >> ################################################## >> #expected args are $logger, $msg, $levelname >> >> @@ -602,8 +687,9 @@ >> my $self = shift; >> if ($self->is_fatal()) { >> $self->fatal(@_); >> - $self->and_die(@_); >> } >> + # no matter what, we die... 'cuz logdie wants you to die. >> + $self->and_die(@_); >> } >> >> ################################################## >> @@ -641,24 +727,26 @@ >> # croaks and confess are FATAL level >> sub logcroak { >> my $self = shift; >> + my $message = Carp::shortmess(@_); >> if ($self->is_fatal()) { >> - my $message = Carp::shortmess(@_); >> foreach (split(/\n/, $message)) { >> $self->fatal("$_\n"); >> } >> - die(noop($message)); >> } >> + # again, we die no matter what >> + die(noop($message)); >> } >> >> sub logconfess { >> my $self = shift; >> + my $message = Carp::longmess(@_); >> if ($self->is_fatal()) { >> - my $message = Carp::longmess(@_); >> foreach (split(/\n/, $message)) { >> $self->fatal("$_\n"); >> } >> - die(noop($message)); >> } >> + # again, we die no matter what >> + die(noop($message)); >> } >> >> ################################################## >> @@ -677,8 +765,8 @@ >> my $self = shift; >> if ($self->is_error()) { >> $self->error(@_); >> - $self->and_die(@_); >> } >> + $self->and_die(@_); >> } >> >> sub inc_level { >> Index: t/001Level.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/001Level.t,v >> retrieving revision 1.1.1.1 >> diff -a -u -r1.1.1.1 001Level.t >> --- t/001Level.t 3 Jul 2002 21:53:33 -0000 1.1.1.1 >> +++ t/001Level.t 9 Sep 2002 02:11:20 -0000 >> @@ -7,7 +7,9 @@ >> # change 'tests => 1' to 'tests => last_test_to_print'; >> ######################### >> use Test; >> -BEGIN { plan tests => 10 }; >> +use strict; >> + >> +BEGIN { plan tests => 20 }; >> use Log::Log4perl::Level; >> BEGIN { >> Log::Log4perl::Level->import("Level"); >> @@ -16,16 +18,23 @@ >> ok(1); # If we made it this far, we're ok. >> >> # Import them into the 'main' namespace; >> -ok($FATAL < $ERROR); >> -ok($ERROR < $INFO); >> -ok($INFO < $DEBUG); >> +foreach ($DEBUG, $INFO, $WARN, $ERROR, $FATAL) { >> + ok(Log::Log4perl::Level::to_level($_)); >> +} >> # Import them into the 'Level' namespace; >> -ok($Level::FATAL < $Level::ERROR); >> -ok($Level::ERROR < $Level::INFO); >> -ok($Level::INFO < $Level::DEBUG); >> +foreach ($Level::DEBUG, $Level::INFO, $Level::WARN, $Level::ERROR, >> $Level::FATAL) { >> + ok(Log::Log4perl::Level::to_level($_)); >> +} >> >> # Import them into the 'My::Level' namespace; >> -ok($My::Level::FATAL < $My::Level::ERROR); >> -ok($My::Level::ERROR < $My::Level::INFO); >> -ok($My::Level::INFO < $My::Level::DEBUG); >> +foreach ($My::Level::DEBUG, $My::Level::INFO, $My::Level::WARN, >> $My::Level::ERROR, $My::Level::FATAL) { >> + ok(Log::Log4perl::Level::to_level($_)); >> +} >> + >> +# ok, now let's check to make sure the relative order is correct. >> + >> +ok(Log::Log4perl::Level::isGreaterOrEqual($DEBUG, $INFO)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($INFO, $WARN)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($WARN, $ERROR)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($ERROR, $FATAL)); >> Index: t/002Logger.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/002Logger.t,v >> retrieving revision 1.14 >> diff -a -u -r1.14 002Logger.t >> --- t/002Logger.t 6 Aug 2002 19:36:25 -0000 1.14 >> +++ t/002Logger.t 9 Sep 2002 02:11:20 -0000 >> @@ -9,10 +9,18 @@ >> use strict; >> >> ######################### >> -# change 'tests => 1' to 'tests => last_test_to_print'; >> -######################### >> -use Test; >> +# used Test::Simple to help debug the test script >> +use Test::Simple tests => 46; >> >> +# to test, as ok() suppresses DEBUG output >> +# my $i = 1; >> +# sub ok { >> +# my ($r, $s) = @_; >> +# print "not " unless ($r); >> +# print "ok ", $i++; >> +# print " - $s" if (defined($s)); >> +# print "\n"; >> +# } >> use Log::Log4perl; >> use Log::Log4perl::Level; >> @@ -30,22 +38,22 @@ >> my $log9 = Log::Log4perl->get_logger("abc::def::ghi"); >> >> # Loggers for the same namespace have to be identical >> -ok($log1 == $log2); >> -ok($log4 == $log5); >> -ok($log6 == $log7); >> -ok($log1 == $log8); >> -ok($log3 == $log9); >> +ok($log1 == $log2, "Log1 same as Log2"); >> +ok($log4 == $log5, "Log4 same as Log5"); >> +ok($log6 == $log7, "Log6 same as Log7"); >> +ok($log1 == $log8, "Log1 same as Log8"); >> +ok($log3 == $log9, "log3 same as Log9"); >> >> # Loggers for different namespaces have to be different >> -ok($log1 != $log3); >> -ok($log3 != $log4); >> -ok($log1 != $log6); >> -ok($log3 != $log6); >> -ok($log5 != $log6); >> -ok($log5 != $log7); >> -ok($log5 != $log1); >> -ok($log7 != $log8); >> -ok($log8 != $log9); >> +ok($log1 != $log3, "Log1 not Log3"); >> +ok($log3 != $log4, "Log3 not Log4"); >> +ok($log1 != $log6, "Log1 not Log6"); >> +ok($log3 != $log6, "Log3 not Log6"); >> +ok($log5 != $log6, "Log5 not Log6"); >> +ok($log5 != $log7, "Log5 not Log7"); >> +ok($log5 != $log1, "Log5 not Log1"); >> +ok($log7 != $log8, "Log7 not Log8"); >> +ok($log8 != $log9, "Log8 not Log9"); >> >> my $app = Log::Log4perl::Appender->new( >> "Log::Log4perl::TestBuffer"); >> @@ -55,10 +63,14 @@ >> ################################################## >> $log1->add_appender($app); >> $log1->level($ERROR); >> + >> +# warn "level is: ", $log1->level(), "\n"; >> + >> $log1->error("Error Message"); >> $log1->debug("Debug Message"); >> -ok($app->buffer(), "ERROR - Error Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\n", "log1 app buffer >> contains ERROR - Error Message"); >> >> +# warn "app buffer is: \"", $app->buffer(), "\"\n"; >> >> ################################################## >> # Allow debug >> @@ -67,7 +79,10 @@ >> $app->buffer(""); >> $log1->error("Error Message"); >> $log1->debug("Debug Message"); >> -ok($app->buffer(), "ERROR - Error Message\nDEBUG - Debug Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\nDEBUG - Debug Message\n", >> + "app buffer contains both ERROR and DEBUG message"); >> + >> +# warn "app buffer is: \"", $app->buffer(), "\"\n"; >> >> ################################################## >> # Multiple Appenders >> @@ -84,8 +99,8 @@ >> $log1->level($ERROR); >> $log1->error("Error Message"); >> #TODO >> -ok($app->buffer(), "ERROR - Error Message\n"); >> -ok($app2->buffer(), "ERROR - Error Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\n", "app buffer contains >> ERROR only"); >> +ok($app2->buffer() eq "ERROR - Error Message\n", "app2 buffer >> contains ERROR only"); >> >> ################################################## >> # Multiple Appenders in different hierarchy levels >> @@ -109,7 +124,7 @@ >> $log1->error("Error Message"); >> >> # Should be distributed to root >> -ok($app3->buffer(), "ERROR - Error Message\n"); >> +ok($app3->buffer() eq "ERROR - Error Message\n", "app3 buffer >> contains ERROR"); >> ################################################## >> # Log in lower levels and propagate to root >> ################################################## >> @@ -121,9 +136,9 @@ >> $log2->add_appender($app2); >> # log3 already has app3 attached >> $log1->error("Error Message"); >> -ok($app->buffer(), "ERROR - Error Message\n"); >> -ok($app2->buffer(), "ERROR - Error Message\n"); >> -ok($app3->buffer(), "ERROR - Error Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\n", "app buffer contains >> ERROR"); >> +ok($app2->buffer() eq "ERROR - Error Message\n", "app2 buffer >> contains ERROR"); >> +ok($app3->buffer() eq "ERROR - Error Message\n", "app3 buffer >> contains ERROR"); >> >> ################################################## >> # Block appenders via priority @@ -137,9 +152,9 @@ >> $log3->level($DEBUG); >> >> $log1->debug("Debug Message"); >> -ok($app->buffer(), ""); >> -ok($app2->buffer(), ""); >> -ok($app3->buffer(), ""); >> +ok($app->buffer() eq "", "app buffer is empty"); >> +ok($app2->buffer() eq "", "app2 buffer is empty"); >> +ok($app3->buffer() eq "", "app3 buffer is empty"); >> >> ################################################## >> # Block via 'false' additivity >> @@ -154,9 +169,9 @@ >> $log3->level($DEBUG); >> >> $log1->debug("Debug Message"); >> -ok($app->buffer(), "DEBUG - Debug Message\n"); >> -ok($app2->buffer(), "DEBUG - Debug Message\n"); >> -ok($app3->buffer(), ""); >> +ok($app->buffer() eq "DEBUG - Debug Message\n", "app buffer contains >> DEBUG"); >> +ok($app2->buffer() eq "DEBUG - Debug Message\n", "app2 buffer >> contains DEBUG"); >> +ok($app3->buffer() eq "", "app3 buffer is empty"); >> >> ################################################## >> # Check is_*() functions >> @@ -165,20 +180,20 @@ >> $log2->level($ERROR); >> $log3->level($INFO); >> >> -ok($log1->is_error(), 1); >> -ok($log1->is_info(), 1); >> -ok($log1->is_fatal(), 1); >> -ok($log1->is_debug(), 1); >> - >> -ok($log2->is_error(), 1); >> -ok($log2->is_info(), ""); >> -ok($log2->is_fatal(), 1); >> -ok($log2->is_debug(), ""); >> - >> -ok($log3->is_error(), 1); >> -ok($log3->is_info(), 1); >> -ok($log3->is_fatal(), 1); >> -ok($log3->is_debug(), ""); >> +ok($log1->is_error(), "log1 is_error == 1"); >> +ok($log1->is_info(), "log1 is_info == 1"); >> +ok($log1->is_fatal(), "log1 is_fatal == 1"); >> +ok($log1->is_debug(), "log1 is_debug == 1"); >> + >> +ok($log2->is_error(), "log2 is_error == 1"); >> +ok(!$log2->is_info(), "log2 is_info == 0"); >> +ok($log2->is_fatal(), "log2 is_fatal == 1"); >> +ok(!$log2->is_debug(), "log2 is_debug == 0"); >> + >> +ok($log3->is_error(), "log3 is_error == 1"); >> +ok($log3->is_info(), "log3 is_info == 1"); >> +ok($log3->is_fatal(), "log3 is_fatal == 1"); >> +ok(!$log3->is_debug(), "log3 is_debug == 0"); >> >> >> ################################################## >> @@ -201,9 +216,12 @@ >> $log3->log($DEBUG, "debug message"); >> $log3->log($INFO, "info message "); >> >> -ok($app->buffer(), "DEBUG - debug message\nINFO - info message \n"); >> -ok($app2->buffer(),"DEBUG - debug message\nINFO - info message \n"); >> -ok($app3->buffer(),"INFO - info message \n"); >> +ok($app->buffer() eq "DEBUG - debug message\nINFO - info message \n", >> + "app buffer contains DEBUG and INFO"); >> +ok($app2->buffer() eq "DEBUG - debug message\nINFO - info message \n", >> + "app2 buffer contains DEBUG"); >> +ok($app3->buffer() eq "INFO - info message \n", >> + "app3 buffer contains INFO"); >> >> ################################################## >> # Check several messages concatenated >> @@ -219,7 +237,7 @@ >> $log1->error("9 ", "10 "); >> $log1->fatal("11 ", "12 ", "13 "); >> >> -ok($app->buffer(), <<EOT); >> +ok($app->buffer() eq <<EOT, "app buffer six lines"); >> DEBUG - 1 2 DEBUG - 3 4 INFO - 5 6 @@ -238,9 +256,11 @@ >> $log1->log($DEBUG, sub { "1" . " " . "2" } ); >> $log1->info(sub { "3 " . "4 " }, sub { "5 " . "6 " }); >> >> -ok($app->buffer(), <<EOT); >> +ok($app->buffer() eq <<EOT, "app buffer contains 2 lines"); >> DEBUG - 1 2 >> INFO - 3 4 5 6 EOT >> >> -BEGIN { plan tests => 46 }; >> +# warn("app buffer is: ", $app->buffer(), "\n"); >> + >> +# BEGIN { plan tests => 46 }; >> Index: t/016Export.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/016Export.t,v >> retrieving revision 1.5 >> diff -a -u -r1.5 016Export.t >> --- t/016Export.t 4 Aug 2002 20:01:40 -0000 1.5 >> +++ t/016Export.t 9 Sep 2002 02:11:24 -0000 >> @@ -18,10 +18,10 @@ >> >> ok(1); >> >> -ok($DEBUG > $ERROR); >> -ok($INFO > $WARN); >> -ok($WARN > $ERROR); >> -ok($ERROR > $FATAL); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($DEBUG, $ERROR)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($INFO, $WARN)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($WARN, $ERROR)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($ERROR, $FATAL)); >> >> ################################################## >> # Init logger >> Index: t/024WarnDieCarp.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/024WarnDieCarp.t,v >> retrieving revision 1.1 >> diff -a -u -r1.1 024WarnDieCarp.t >> --- t/024WarnDieCarp.t 29 Aug 2002 05:33:28 -0000 1.1 >> +++ t/024WarnDieCarp.t 9 Sep 2002 02:11:25 -0000 >> @@ -46,6 +46,17 @@ >> ok($app->buffer() !~ /$out_str/, "$mname($in_str): Buffer does NOT >> contain \"$out_str\""); >> } >> >> +# same as above, just look for no output in buffer, but output in >> STDERR >> +sub dietest_nooutput { >> + my ($method, $in_str, $out_str, $app, $mname) = @_; >> + >> + eval { &$method($in_str) }; >> + + ok($warnstr =~ /$out_str/, "$mname($in_str): STDERR contains >> \"$out_str\""); >> + ok($app->buffer() !~ /$out_str/, "$mname($in_str): Buffer does NOT >> contain \"$out_str\""); >> +} >> + >> + >> ok(1, "Initialized OK"); >> ############################################################ >> @@ -94,13 +105,12 @@ >> >> $log->level($OFF); # $OFF == $FATAL... although I suspect that's a >> bug in the log4j spec >> >> -foreach my $f ("logwarn", "logcarp", "logcluck", >> - "error_warn", "error_die") { >> +foreach my $f ("logwarn", "logcarp", "logcluck", "error_warn") { >> warndietest_nooutput(sub {$log->$f(@_)}, "Test $test: $f", "Test >> $test: $f", $app, "$f"); >> $test++; >> } >> >> -foreach my $f ("logdie", "logcroak", "logconfess") { >> - warndietest(sub {$log->$f(@_)}, "Test $test: $f", "Test $test: >> $f", $app, "$f"); >> +foreach my $f ("error_die", "logdie", "logcroak", "logconfess") { >> + dietest_nooutput(sub {$log->$f(@_)}, "Test $test: $f", "Test >> $test: $f", $app, "$f"); >> $test++; >> } >> Index: t/025CustLevels.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/025CustLevels.t,v >> retrieving revision 1.1 >> diff -a -u -r1.1 025CustLevels.t >> --- t/025CustLevels.t 3 Sep 2002 18:09:42 -0000 1.1 >> +++ t/025CustLevels.t 9 Sep 2002 02:11:26 -0000 >> @@ -1,6 +1,7 @@ >> ########################################### >> # Test Suite for Log::Log4perl::Config >> -# Mike Schilli, 2002 (m...@pe...) >> +# Erik Selberg, (c) 2002 er...@se... >> +# clone of 025CustLevels.t but uses nicer method (?) we hope >> ########################################### >> >> ######################### >> @@ -9,26 +10,61 @@ >> use Test; >> >> #create a custom level "LITEWARN" >> -BEGIN { >> -package Log::Log4perl::Level; >> -our %PRIORITY = ( >> - "FATAL" => 0, >> - "ERROR" => 3, >> - "WARN" => 4, >> - "LITEWARN" => 5, >> - "INFO" => 6, >> - "DEBUG" => 7, >> -); >> -} >> - >> - >> use Log::Log4perl; >> use Log::Log4perl::Level; >> use Log::Log4perl::TestBuffer; >> +# use strict; >> >> >> ok(1); # If we made it this far, we're ok. >> >> +Log::Log4perl::Logger::create_custom_level("LITEWARN", "WARN"); >> + >> +# test insane creation of levels >> + >> +foreach (1 .. 14) { >> + ok(Log::Log4perl::Logger::create_custom_level("TEST$_", "INFO"), 0); >> +} >> + >> +# 15th should fail.. this assumes that each level is 10000 apart from >> +# the other. >> + >> +ok(eval { Log::Log4perl::Logger::create_custom_level("TEST15", >> "INFO") }, + undef); >> + >> +# now, by re-arranging (as we whine about in create_custom_levels), we >> +# should be able to get 15. >> + >> +my %btree = ( >> + 8 => "DEBUG", >> + 4 => 8, >> + 2 => 4, >> + 1 => 2, >> + 3 => 4, >> + 6 => 8, >> + 5 => 6, >> + 7 => 8, >> + 12 => "DEBUG", >> + 10 => 12, >> + 9 => 10, >> + 11 => 12, >> + 14 => "DEBUG", >> + 13 => 14, >> + 15 => "DEBUG", >> + ); >> + >> +foreach (8, 4, 2, 1, 3, 6, 5, 7, 12, 10, 9, 11, 14, 13, 15) { >> + my $level = $btree{$_} eq "DEBUG" ? "DEBUG" : "BTREE$btree{$_}"; >> +# warn("Creating BTREE$_ after $level"); >> + ok(Log::Log4perl::Logger::create_custom_level("BTREE$_", $level), 0); >> +# warn("BTREE$_ is ", ${Log::Log4perl::Level::PRIORITY{"BTREE$_"}}); >> +} >> + >> +# foreach (1 .. 15) { >> +# warn("BTREE$_ is: ", >> ${Log::Log4perl::Level::PRIORITY{"BTREE$_"}}); >> +# } >> + >> + >> my $LOGFILE = "example.log"; >> unlink $LOGFILE; >> >> @@ -40,10 +76,16 @@ >> EOT >> >> >> - >> Log::Log4perl::init(\$config); >> >> >> +# can't create a custom level after init... let's test that. Just look >> +# for an undef (i.e. failure) from the eval >> + >> +ok(eval { Log::Log4perl::Logger::create_custom_level("NOTIFY", >> "WARN"); }, >> + undef); >> + >> + >> # ********************* >> # check a category logger >> >> @@ -76,6 +118,7 @@ >> >> $logger->log($WARN, "a warning message"); >> $logger->log($LITEWARN, "a LITE warning message"); >> +die("lame hack to suppress warning") if ($LITEWARN != $LITEWARN); >> $logger->log($DEBUG, "an info message, should not log"); >> >> open FILE, "<$LOGFILE" or die "Cannot open $LOGFILE"; >> @@ -92,9 +135,12 @@ >> ok(! $logger->is_info); >> >> >> +# warn("Testing inc_level()"); >> + >> #*************************** >> #increase/decrease leves >> -$logger->inc_level(); #bump up from litewarn to warn >> +$logger->inc_level(1); #bump up from litewarn to warn >> +# warn("level is now: ", $logger->level()); >> ok($logger->is_warn); >> ok(!$logger->is_litewarn); >> ok(!$logger->is_info); >> @@ -107,14 +153,15 @@ >> my $result4 = "WARN - after bumping, warning message\n"; >> ok($data, "$result1$result2$result3$result4"); >> >> - >> $logger->dec_level(2); #bump down from warn to litewarn to info >> + >> ok($logger->is_warn); >> ok($logger->is_litewarn); >> ok($logger->is_info); >> + >> ok(! $logger->is_debug) ; >> >> >> -BEGIN { plan tests => 15 }; >> +BEGIN { plan tests => 46 }; >> >> unlink $LOGFILE; >> >> > > > |
From: Erik S. <er...@se...> - 2002-09-09 08:13:55
|
msc...@ao... wrote: >>Maybe Mozilla is doing weird stuff... anyway, I >>re-confirmed that the patch works. But to make life >>easy, I put it up on my website. >> >> > >Interesting. Can you confirm the patch works even after you send mail to yourself? > >Anyway, the patch on your website worked (yay!) like a charm. Couple of questions/requests on your changes: > >* Looks like the error message here got garbeled (Logger.pm): > > my $after = shift || die("create_custom_level: forgot to pass in an after string! > > Isn't garbled, just confusing I think. :) "after" was the variable referring to the level after which to place the custom one. Updated. >* What's the purpose of > > our %PRIORITY = (); # unless (%PRIORITY); > our %LEVELS = () unless (%LEVELS); > our %SYSLOG = () unless (%SYSLOG); > > >And why the '#' in the first line? > > the "our" is there to state that there are three globals, although they aren't created there. I think in retrospect however, those should be "my's". The #unless bit was a bit of a hack to not set PRIORITY to empty if something else loaded it and set it first, although I don't believe that can happen now. >* Documentation: Can you add a couple of lines to Log::Log4perl.pm to show how to use the custom level features? > > Yup. >* Why the logic > > # figure out new int value by AFTER + (AFTER+ 1) / 2 > >if you could just store the priorities defined so far orderly in an array and switch to the next/previous element? > > Mostly to work within this entire PRIORITY / LEVEL thing we have going... it'd be much nicer if we just had a linked list construct and could insert things in and so forth. I think it'd be a good thing to potentially redesign. Course, it WILL most likely break from log4j in that they are somewhat tied to INTs -- they just make the user subclass and pick the new FOO_INT to use. >* # This is a bit better way to create code on the fly than eval'ing strings. > # -erik > >Nice. Does this mean they're (-d) debuggable now? Could we go all the way and use this in set_output_methods() as well? > > yawp, although I'll leave that for later (set_output_methods) >Looks like your foreach loop is outside the subroutine and therefore only called when the module is loaded: > > #now lets autogenerate the logger subs based on the defined priorities > foreach my $level (keys %Log::Log4perl::Level::PRIORITY){ > create_log_level_methods($level); >} > >Would be great if you could shed some light on these >issues ... :) > > Right, that's the idea... this creates the initial ones (DEBUG .. FATAL). >-- Mike > >Mike Schilli >log...@pe... >http://perlmeister.com > > > > ------------------------------------------------------------------------ > > Subject: > Re: Release 0.23 because of upcoming article? > From: > er...@se... > Date: > Sun, 08 Sep 2002 20:50:42 -0700 > To: > "Erik W. Selberg" <er...@se...> > > > > Maybe Mozilla is doing weird stuff... anyway, I re-confirmed that the > patch works. But to make life easy, I put it up on my website. > > http://speedstation.whizzyfoo.com/Log-Log4perl/custlevel3.patch > > Note: Log4perl.patchable is just a copy of a fresh checkout. > > 121 speedstation:Log-Log4perl.patchable >patch -p0 < ../custlevel3.patch > patching file lib/Log/Log4perl/Appender.pm > patching file lib/Log/Log4perl/Level.pm > patching file lib/Log/Log4perl/Logger.pm > patching file t/001Level.t > patching file t/002Logger.t > patching file t/016Export.t > patching file t/024WarnDieCarp.t > patching file t/025CustLevels.t > 122 speedstation:Log-Log4perl.patchable > > > -e > > Erik W. Selberg wrote: > >> Hmm.... that's what I did. >> >> Well, here goes again. Can ya let me know what the output of patch is >> if it doesn't go through? >> >> Thanks, >> -e >> >> msc...@ao... wrote: >> >>> In a message dated Sun, 8 Sep 2002 4:31:30 AM Eastern Standard Time, >>> er...@se... writes: >>> >>> >>> >>>> Please apply the patch.. >>>> >>> >>> >>> >>> Ok ... just tried to apply your latest patch, unfortunately it >>> doesn't go through -- maybe it's my email client mangling the lines, >>> so please >>> >>> 1) use "cvs diff -Nau" of your local dir against CVS >>> 2) send the patch as an attachment >>> >>> Thanks! >>> >>> -- Mike >>> >>> Mike Schilli >>> log...@pe... >>> http://perlmeister.com >>> >>> >>> >> >> >> ------------------------------------------------------------------------ >> >> ? out.txt >> Index: lib/Log/Log4perl/Appender.pm >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Appender.pm,v >> retrieving revision 1.8 >> diff -a -u -r1.8 Appender.pm >> --- lib/Log/Log4perl/Appender.pm 21 Aug 2002 07:52:51 -0000 1.8 >> +++ lib/Log/Log4perl/Appender.pm 9 Sep 2002 02:11:14 -0000 >> @@ -83,8 +83,9 @@ >> >> # Check if the appender has a last-minute veto in form >> # of an "appender threshold" >> - if($self->{level} < $ >> + if($self->{level} > $ >> Log::Log4perl::Level::PRIORITY{$level}) { >> + print "$self->{level} > $level, aborting\n" if DEBUG; >> return; >> } >> >> Index: lib/Log/Log4perl/Level.pm >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Level.pm,v >> retrieving revision 1.6 >> diff -a -u -r1.6 Level.pm >> --- lib/Log/Log4perl/Level.pm 3 Sep 2002 18:12:17 -0000 1.6 >> +++ lib/Log/Log4perl/Level.pm 9 Sep 2002 02:11:16 -0000 >> @@ -7,22 +7,44 @@ >> use warnings; >> use Carp; >> >> +# log4j, for whatever reason, puts 0 as all and MAXINT as OFF. >> +# this seems less optimal, as more logging would imply a higher >> +# level. But oh well. Probably some brokenness that has persisted. :) >> +use constant ALL_INT => 0; >> +use constant DEBUG_INT => 10000; >> +use constant INFO_INT => 20000; >> +use constant WARN_INT => 30000; >> +use constant ERROR_INT => 40000; >> +use constant FATAL_INT => 50000; >> +use constant OFF_INT => (2 ** 31) - 1; >> + >> no strict qw(refs); >> +use vars qw(%PRIORITY %LEVELS); >> + >> +our %PRIORITY = (); # unless (%PRIORITY); >> +our %LEVELS = () unless (%LEVELS); >> +our %SYSLOG = () unless (%SYSLOG); >> + >> +sub add_priority { >> + my ($prio, $intval, $syslog) = @_; >> + $prio = uc($prio); # just in case; >> + >> + $PRIORITY{$prio} = $intval; >> + $LEVELS{$intval} = $prio; >> + $SYSLOG{$prio} = $syslog if defined($syslog); >> +} >> + >> +# create the basic priorities >> +add_priority("OFF", OFF_INT, -1); >> +add_priority("FATAL", FATAL_INT, 0); >> +add_priority("ERROR", ERROR_INT, 3); >> +add_priority("WARN", WARN_INT, 4); >> +add_priority("INFO", INFO_INT, 6); >> +add_priority("DEBUG", DEBUG_INT, 7); >> +add_priority("ALL", ALL_INT, 7); >> >> -our %PRIORITY = ( >> - "FATAL" => 0, >> - "ERROR" => 3, >> - "WARN" => 4, >> - "INFO" => 6, >> - "DEBUG" => 7, >> -) unless %PRIORITY; >> - >> - # Reverse mapping >> -our %LEVELS = map { $PRIORITY{$_} => $_ } keys %PRIORITY; >> - >> - # Min and max >> -$PRIORITY{'OFF'} = $PRIORITY{'FATAL'}; >> -$PRIORITY{'ALL'} = $PRIORITY{'DEBUG'}; >> +# we often sort numerically, so a helper func for readability >> +sub numerically {$a <=> $b} >> >> ########################################### >> sub import { >> @@ -43,6 +65,9 @@ >> my $name = "$namespace$key"; >> my $value = $PRIORITY{$key}; >> *{"$name"} = \$value; >> + my $nameint = "$namespace${key}_INT"; >> + my $func = uc($key) . "_INT"; >> + *{"$nameint"} = \&$func; >> } >> } >> >> @@ -75,8 +100,11 @@ >> if (exists $LEVELS{$priority}) { >> return $LEVELS{$priority} >> }else { >> - die "priority '$priority' is not a valid error level number >> (".join ('|', keys %LEVELS),')'; >> + die("priority '$priority' is not a valid error level number (", >> + join("|", sort numerically keys %LEVELS), " >> + )"); >> } >> + >> } >> >> ################################################## >> @@ -120,8 +148,9 @@ >> >> foreach (1..$delta){ >> #so the list is DEBUG, INFO, WARN, ERROR, FATAL >> - foreach my $p (reverse sort keys %LEVELS){ >> - if ($p < $old_priority) { >> + # but remember, the numbers go in reverse order! >> + foreach my $p (sort numerically keys %LEVELS){ >> + if ($p > $old_priority) { >> $new_priority = $p; >> last; >> } >> @@ -140,8 +169,9 @@ >> >> foreach (1..$delta){ >> #so the list is FATAL, ERROR, WARN, INFO, DEBUG >> - foreach my $p (sort keys %LEVELS){ >> - if ($p > $old_priority) { >> + # but remember, the numbers go in reverse order! >> + foreach my $p (reverse sort numerically keys %LEVELS){ >> + if ($p < $old_priority) { >> $new_priority = $p; >> last; >> } >> @@ -150,6 +180,25 @@ >> } >> return $new_priority; >> } >> + >> +sub isGreaterOrEqual { >> + my $lval = shift; >> + my $rval = shift; >> + + # in theory, we should check if the above really ARE valid levels. >> + # but we just use numeric comparison, since they aren't really >> classes. >> + >> + # oh, yeah, and 'cuz level ints go from 0 .. N with 0 being highest, >> + # these are reversed. >> + return $lval <= $rval; >> +} >> + >> +###################################################################### >> +# +# since the integer representation of levels is reversed from what >> +# we normally want, we don't want to use < and >... instead, we >> +# want to use this comparison function >> + >> >> 1; >> >> Index: lib/Log/Log4perl/Logger.pm >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/lib/Log/Log4perl/Logger.pm,v >> retrieving revision 1.25 >> diff -a -u -r1.25 Logger.pm >> --- lib/Log/Log4perl/Logger.pm 3 Sep 2002 18:13:41 -0000 1.25 >> +++ lib/Log/Log4perl/Logger.pm 9 Sep 2002 02:11:20 -0000 >> @@ -139,8 +139,11 @@ >> >> my %priority = %Log::Log4perl::Level::PRIORITY; #convenience and cvs >> >> + # changed to >= from <= as level ints were reversed >> foreach my $levelname (keys %priority){ >> - if ($priority{$levelname} <= $level) { >> + if (Log::Log4perl::Level::isGreaterOrEqual($level, >> + $priority{$levelname} >> + )) { >> print " ($priority{$levelname} <= $level)\n" >> if DEBUG; >> $self->{$levelname} = $coderef; >> @@ -467,6 +470,8 @@ >> ################################################## >> my ($self, $priority, @messages) = @_; >> >> + confess("log: No priority given!") unless defined($priority); >> + >> # Just in case of 'init_and_watch' -- see Changes 0.21 >> $_[0] = $LOGGERS_BY_NAME->{$_[0]->{category}} if defined >> $LAST_CHECKED_AT; >> >> @@ -480,31 +485,111 @@ >> Log::Log4perl::Level::to_level($priority)); >> } >> >> +###################################################################### >> +# >> +# create_custom_level +# creates a custom level >> +# in theory, could be used to create the default ones >> >> -#now lets autogenerate the logger subs based on the defined priorities >> -foreach my $level (keys %Log::Log4perl::Level::PRIORITY){ >> +sub create_custom_level { >> + my $level = shift || die("create_custom_level: forgot to pass in a >> level string!"); >> + my $after = shift || die("create_custom_level: forgot to pass in >> an after string!"); >> + my $syslog_equiv = shift; # can be undef >> >> - my $lclevel = lc $level; >> - my $code = <<EOL; >> + ## only let users create custom levels before initialization >> >> - sub $lclevel { >> - print "$lclevel: (\$_[0]->{category}/\$_[0]->{level}) >> [\@_]\n" if DEBUG; >> - init_warn() unless \$INITIALIZED; >> - \$_[0]->{$level}(\@_, '$level'); >> - } >> - - sub is_$lclevel { return \$_[0]->level() >= \$$level; } >> -EOL >> + die("create_custom_level must be called before init or first >> get_logger() call") if ($INITIALIZED); >> >> - eval $code; >> + my %PRIORITY = %Log::Log4perl::Level::PRIORITY; #convenience >> >> - if ($@) { >> - die "Log4perl init failed, could not define a subroutine for >> $level:\n$code\n$@"; >> - } >> + die("create_custom_level: no such level \"$after\"! Use one of: ", >> join(", ", sort keys %PRIORITY)) >> + unless $PRIORITY{$after}; >> + >> + # figure out new int value by AFTER + (AFTER+ 1) / 2 >> + >> + my $next_prio = >> Log::Log4perl::Level::get_lower_level($PRIORITY{$after}, 1); >> + my $cust_prio = int(($PRIORITY{$after} + $next_prio) / 2); >> + >> +# CORE::warn("Creating prio $cust_prio between $PRIORITY{$after} >> and $next_prio"); >> + >> + die(qq{create_custom_level: Calculated level of $cust_prio already >> exists! >> + This should only happen if you've made some insane number of >> custom >> + levels (like 15 one after another) >> + You can usually fix this by re-arranging your code from: >> + create_custom_level("cust1", X); >> + create_custom_level("cust2", X); >> + create_custom_level("cust3", X); >> + create_custom_level("cust4", X); >> + create_custom_level("cust5", X); >> + into: >> + create_custom_level("cust3", X); >> + create_custom_level("cust5", X); >> + create_custom_level("cust4", 4); >> + create_custom_level("cust2", cust3); >> + create_custom_level("cust1", cust2); >> + }) if ($Log::Log4perl::Level::LEVELS{$cust_prio}); >> + >> + Log::Log4perl::Level::add_priority($level, $cust_prio, >> $syslog_equiv); >> + >> + print("Adding prio $level at $cust_prio\n") if DEBUG; >> + >> + # get $LEVEL into namespace of Log::Log4perl::Logger to + # >> create $logger->foo nd $logger->is_foo >> + my $name = "Log::Log4perl::Logger::"; >> + my $key = $level; >> + >> + no strict qw(refs); >> + # be sure to use ${Log...} as CVS adds log entries for Log >> + *{"$name$key"} = \${Log::Log4perl::Level::PRIORITY{$level}}; >> >> + # now, stick it in the caller's namespace >> + $name = caller(0) . "::"; >> + *{"$name$key"} = \${Log::Log4perl::Level::PRIORITY{$level}}; >> + use strict qw(refs); >> + >> + create_log_level_methods($level); >> + >> + return 0; >> >> } >> >> +######################################## >> +# >> +# if we were hackin' lisp (or scheme), we'd be returning some lambda >> +# expressions. But we aren't. :) So we'll just create some strings and >> +# eval them. >> +sub create_log_level_methods { >> + my $level = shift || die("create_log_level_methods: forgot to pass >> in a level string!"); >> + my $lclevel = lc($level); >> + my $levelint = uc($level) . "_INT"; >> + >> + no strict qw(refs); >> + >> + # This is a bit better way to create code on the fly than eval'ing >> strings. >> + # -erik >> + >> + *{__PACKAGE__ . "::$lclevel"} = sub { >> + print "$lclevel: ($_[0]->{category}/$_[0]->{level}) [@_]\n" >> if DEBUG; >> + init_warn() unless $INITIALIZED; >> + $_[0]->{$level}(@_, $level); >> + }; >> + >> + *{__PACKAGE__ . "::is_$lclevel"} = sub { + return >> Log::Log4perl::Level::isGreaterOrEqual($_[0]->level(), >> + $$level); + }; >> + + use strict qw(refs); >> + >> + return 0; >> + >> +} >> + >> +#now lets autogenerate the logger subs based on the defined priorities >> +foreach my $level (keys %Log::Log4perl::Level::PRIORITY){ >> + create_log_level_methods($level); >> +} >> + >> ################################################## >> #expected args are $logger, $msg, $levelname >> >> @@ -602,8 +687,9 @@ >> my $self = shift; >> if ($self->is_fatal()) { >> $self->fatal(@_); >> - $self->and_die(@_); >> } >> + # no matter what, we die... 'cuz logdie wants you to die. >> + $self->and_die(@_); >> } >> >> ################################################## >> @@ -641,24 +727,26 @@ >> # croaks and confess are FATAL level >> sub logcroak { >> my $self = shift; >> + my $message = Carp::shortmess(@_); >> if ($self->is_fatal()) { >> - my $message = Carp::shortmess(@_); >> foreach (split(/\n/, $message)) { >> $self->fatal("$_\n"); >> } >> - die(noop($message)); >> } >> + # again, we die no matter what >> + die(noop($message)); >> } >> >> sub logconfess { >> my $self = shift; >> + my $message = Carp::longmess(@_); >> if ($self->is_fatal()) { >> - my $message = Carp::longmess(@_); >> foreach (split(/\n/, $message)) { >> $self->fatal("$_\n"); >> } >> - die(noop($message)); >> } >> + # again, we die no matter what >> + die(noop($message)); >> } >> >> ################################################## >> @@ -677,8 +765,8 @@ >> my $self = shift; >> if ($self->is_error()) { >> $self->error(@_); >> - $self->and_die(@_); >> } >> + $self->and_die(@_); >> } >> >> sub inc_level { >> Index: t/001Level.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/001Level.t,v >> retrieving revision 1.1.1.1 >> diff -a -u -r1.1.1.1 001Level.t >> --- t/001Level.t 3 Jul 2002 21:53:33 -0000 1.1.1.1 >> +++ t/001Level.t 9 Sep 2002 02:11:20 -0000 >> @@ -7,7 +7,9 @@ >> # change 'tests => 1' to 'tests => last_test_to_print'; >> ######################### >> use Test; >> -BEGIN { plan tests => 10 }; >> +use strict; >> + >> +BEGIN { plan tests => 20 }; >> use Log::Log4perl::Level; >> BEGIN { >> Log::Log4perl::Level->import("Level"); >> @@ -16,16 +18,23 @@ >> ok(1); # If we made it this far, we're ok. >> >> # Import them into the 'main' namespace; >> -ok($FATAL < $ERROR); >> -ok($ERROR < $INFO); >> -ok($INFO < $DEBUG); >> +foreach ($DEBUG, $INFO, $WARN, $ERROR, $FATAL) { >> + ok(Log::Log4perl::Level::to_level($_)); >> +} >> # Import them into the 'Level' namespace; >> -ok($Level::FATAL < $Level::ERROR); >> -ok($Level::ERROR < $Level::INFO); >> -ok($Level::INFO < $Level::DEBUG); >> +foreach ($Level::DEBUG, $Level::INFO, $Level::WARN, $Level::ERROR, >> $Level::FATAL) { >> + ok(Log::Log4perl::Level::to_level($_)); >> +} >> >> # Import them into the 'My::Level' namespace; >> -ok($My::Level::FATAL < $My::Level::ERROR); >> -ok($My::Level::ERROR < $My::Level::INFO); >> -ok($My::Level::INFO < $My::Level::DEBUG); >> +foreach ($My::Level::DEBUG, $My::Level::INFO, $My::Level::WARN, >> $My::Level::ERROR, $My::Level::FATAL) { >> + ok(Log::Log4perl::Level::to_level($_)); >> +} >> + >> +# ok, now let's check to make sure the relative order is correct. >> + >> +ok(Log::Log4perl::Level::isGreaterOrEqual($DEBUG, $INFO)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($INFO, $WARN)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($WARN, $ERROR)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($ERROR, $FATAL)); >> Index: t/002Logger.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/002Logger.t,v >> retrieving revision 1.14 >> diff -a -u -r1.14 002Logger.t >> --- t/002Logger.t 6 Aug 2002 19:36:25 -0000 1.14 >> +++ t/002Logger.t 9 Sep 2002 02:11:20 -0000 >> @@ -9,10 +9,18 @@ >> use strict; >> >> ######################### >> -# change 'tests => 1' to 'tests => last_test_to_print'; >> -######################### >> -use Test; >> +# used Test::Simple to help debug the test script >> +use Test::Simple tests => 46; >> >> +# to test, as ok() suppresses DEBUG output >> +# my $i = 1; >> +# sub ok { >> +# my ($r, $s) = @_; >> +# print "not " unless ($r); >> +# print "ok ", $i++; >> +# print " - $s" if (defined($s)); >> +# print "\n"; >> +# } >> use Log::Log4perl; >> use Log::Log4perl::Level; >> @@ -30,22 +38,22 @@ >> my $log9 = Log::Log4perl->get_logger("abc::def::ghi"); >> >> # Loggers for the same namespace have to be identical >> -ok($log1 == $log2); >> -ok($log4 == $log5); >> -ok($log6 == $log7); >> -ok($log1 == $log8); >> -ok($log3 == $log9); >> +ok($log1 == $log2, "Log1 same as Log2"); >> +ok($log4 == $log5, "Log4 same as Log5"); >> +ok($log6 == $log7, "Log6 same as Log7"); >> +ok($log1 == $log8, "Log1 same as Log8"); >> +ok($log3 == $log9, "log3 same as Log9"); >> >> # Loggers for different namespaces have to be different >> -ok($log1 != $log3); >> -ok($log3 != $log4); >> -ok($log1 != $log6); >> -ok($log3 != $log6); >> -ok($log5 != $log6); >> -ok($log5 != $log7); >> -ok($log5 != $log1); >> -ok($log7 != $log8); >> -ok($log8 != $log9); >> +ok($log1 != $log3, "Log1 not Log3"); >> +ok($log3 != $log4, "Log3 not Log4"); >> +ok($log1 != $log6, "Log1 not Log6"); >> +ok($log3 != $log6, "Log3 not Log6"); >> +ok($log5 != $log6, "Log5 not Log6"); >> +ok($log5 != $log7, "Log5 not Log7"); >> +ok($log5 != $log1, "Log5 not Log1"); >> +ok($log7 != $log8, "Log7 not Log8"); >> +ok($log8 != $log9, "Log8 not Log9"); >> >> my $app = Log::Log4perl::Appender->new( >> "Log::Log4perl::TestBuffer"); >> @@ -55,10 +63,14 @@ >> ################################################## >> $log1->add_appender($app); >> $log1->level($ERROR); >> + >> +# warn "level is: ", $log1->level(), "\n"; >> + >> $log1->error("Error Message"); >> $log1->debug("Debug Message"); >> -ok($app->buffer(), "ERROR - Error Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\n", "log1 app buffer >> contains ERROR - Error Message"); >> >> +# warn "app buffer is: \"", $app->buffer(), "\"\n"; >> >> ################################################## >> # Allow debug >> @@ -67,7 +79,10 @@ >> $app->buffer(""); >> $log1->error("Error Message"); >> $log1->debug("Debug Message"); >> -ok($app->buffer(), "ERROR - Error Message\nDEBUG - Debug Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\nDEBUG - Debug Message\n", >> + "app buffer contains both ERROR and DEBUG message"); >> + >> +# warn "app buffer is: \"", $app->buffer(), "\"\n"; >> >> ################################################## >> # Multiple Appenders >> @@ -84,8 +99,8 @@ >> $log1->level($ERROR); >> $log1->error("Error Message"); >> #TODO >> -ok($app->buffer(), "ERROR - Error Message\n"); >> -ok($app2->buffer(), "ERROR - Error Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\n", "app buffer contains >> ERROR only"); >> +ok($app2->buffer() eq "ERROR - Error Message\n", "app2 buffer >> contains ERROR only"); >> >> ################################################## >> # Multiple Appenders in different hierarchy levels >> @@ -109,7 +124,7 @@ >> $log1->error("Error Message"); >> >> # Should be distributed to root >> -ok($app3->buffer(), "ERROR - Error Message\n"); >> +ok($app3->buffer() eq "ERROR - Error Message\n", "app3 buffer >> contains ERROR"); >> ################################################## >> # Log in lower levels and propagate to root >> ################################################## >> @@ -121,9 +136,9 @@ >> $log2->add_appender($app2); >> # log3 already has app3 attached >> $log1->error("Error Message"); >> -ok($app->buffer(), "ERROR - Error Message\n"); >> -ok($app2->buffer(), "ERROR - Error Message\n"); >> -ok($app3->buffer(), "ERROR - Error Message\n"); >> +ok($app->buffer() eq "ERROR - Error Message\n", "app buffer contains >> ERROR"); >> +ok($app2->buffer() eq "ERROR - Error Message\n", "app2 buffer >> contains ERROR"); >> +ok($app3->buffer() eq "ERROR - Error Message\n", "app3 buffer >> contains ERROR"); >> >> ################################################## >> # Block appenders via priority @@ -137,9 +152,9 @@ >> $log3->level($DEBUG); >> >> $log1->debug("Debug Message"); >> -ok($app->buffer(), ""); >> -ok($app2->buffer(), ""); >> -ok($app3->buffer(), ""); >> +ok($app->buffer() eq "", "app buffer is empty"); >> +ok($app2->buffer() eq "", "app2 buffer is empty"); >> +ok($app3->buffer() eq "", "app3 buffer is empty"); >> >> ################################################## >> # Block via 'false' additivity >> @@ -154,9 +169,9 @@ >> $log3->level($DEBUG); >> >> $log1->debug("Debug Message"); >> -ok($app->buffer(), "DEBUG - Debug Message\n"); >> -ok($app2->buffer(), "DEBUG - Debug Message\n"); >> -ok($app3->buffer(), ""); >> +ok($app->buffer() eq "DEBUG - Debug Message\n", "app buffer contains >> DEBUG"); >> +ok($app2->buffer() eq "DEBUG - Debug Message\n", "app2 buffer >> contains DEBUG"); >> +ok($app3->buffer() eq "", "app3 buffer is empty"); >> >> ################################################## >> # Check is_*() functions >> @@ -165,20 +180,20 @@ >> $log2->level($ERROR); >> $log3->level($INFO); >> >> -ok($log1->is_error(), 1); >> -ok($log1->is_info(), 1); >> -ok($log1->is_fatal(), 1); >> -ok($log1->is_debug(), 1); >> - >> -ok($log2->is_error(), 1); >> -ok($log2->is_info(), ""); >> -ok($log2->is_fatal(), 1); >> -ok($log2->is_debug(), ""); >> - >> -ok($log3->is_error(), 1); >> -ok($log3->is_info(), 1); >> -ok($log3->is_fatal(), 1); >> -ok($log3->is_debug(), ""); >> +ok($log1->is_error(), "log1 is_error == 1"); >> +ok($log1->is_info(), "log1 is_info == 1"); >> +ok($log1->is_fatal(), "log1 is_fatal == 1"); >> +ok($log1->is_debug(), "log1 is_debug == 1"); >> + >> +ok($log2->is_error(), "log2 is_error == 1"); >> +ok(!$log2->is_info(), "log2 is_info == 0"); >> +ok($log2->is_fatal(), "log2 is_fatal == 1"); >> +ok(!$log2->is_debug(), "log2 is_debug == 0"); >> + >> +ok($log3->is_error(), "log3 is_error == 1"); >> +ok($log3->is_info(), "log3 is_info == 1"); >> +ok($log3->is_fatal(), "log3 is_fatal == 1"); >> +ok(!$log3->is_debug(), "log3 is_debug == 0"); >> >> >> ################################################## >> @@ -201,9 +216,12 @@ >> $log3->log($DEBUG, "debug message"); >> $log3->log($INFO, "info message "); >> >> -ok($app->buffer(), "DEBUG - debug message\nINFO - info message \n"); >> -ok($app2->buffer(),"DEBUG - debug message\nINFO - info message \n"); >> -ok($app3->buffer(),"INFO - info message \n"); >> +ok($app->buffer() eq "DEBUG - debug message\nINFO - info message \n", >> + "app buffer contains DEBUG and INFO"); >> +ok($app2->buffer() eq "DEBUG - debug message\nINFO - info message \n", >> + "app2 buffer contains DEBUG"); >> +ok($app3->buffer() eq "INFO - info message \n", >> + "app3 buffer contains INFO"); >> >> ################################################## >> # Check several messages concatenated >> @@ -219,7 +237,7 @@ >> $log1->error("9 ", "10 "); >> $log1->fatal("11 ", "12 ", "13 "); >> >> -ok($app->buffer(), <<EOT); >> +ok($app->buffer() eq <<EOT, "app buffer six lines"); >> DEBUG - 1 2 DEBUG - 3 4 INFO - 5 6 @@ -238,9 +256,11 @@ >> $log1->log($DEBUG, sub { "1" . " " . "2" } ); >> $log1->info(sub { "3 " . "4 " }, sub { "5 " . "6 " }); >> >> -ok($app->buffer(), <<EOT); >> +ok($app->buffer() eq <<EOT, "app buffer contains 2 lines"); >> DEBUG - 1 2 >> INFO - 3 4 5 6 EOT >> >> -BEGIN { plan tests => 46 }; >> +# warn("app buffer is: ", $app->buffer(), "\n"); >> + >> +# BEGIN { plan tests => 46 }; >> Index: t/016Export.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/016Export.t,v >> retrieving revision 1.5 >> diff -a -u -r1.5 016Export.t >> --- t/016Export.t 4 Aug 2002 20:01:40 -0000 1.5 >> +++ t/016Export.t 9 Sep 2002 02:11:24 -0000 >> @@ -18,10 +18,10 @@ >> >> ok(1); >> >> -ok($DEBUG > $ERROR); >> -ok($INFO > $WARN); >> -ok($WARN > $ERROR); >> -ok($ERROR > $FATAL); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($DEBUG, $ERROR)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($INFO, $WARN)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($WARN, $ERROR)); >> +ok(Log::Log4perl::Level::isGreaterOrEqual($ERROR, $FATAL)); >> >> ################################################## >> # Init logger >> Index: t/024WarnDieCarp.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/024WarnDieCarp.t,v >> retrieving revision 1.1 >> diff -a -u -r1.1 024WarnDieCarp.t >> --- t/024WarnDieCarp.t 29 Aug 2002 05:33:28 -0000 1.1 >> +++ t/024WarnDieCarp.t 9 Sep 2002 02:11:25 -0000 >> @@ -46,6 +46,17 @@ >> ok($app->buffer() !~ /$out_str/, "$mname($in_str): Buffer does NOT >> contain \"$out_str\""); >> } >> >> +# same as above, just look for no output in buffer, but output in >> STDERR >> +sub dietest_nooutput { >> + my ($method, $in_str, $out_str, $app, $mname) = @_; >> + >> + eval { &$method($in_str) }; >> + + ok($warnstr =~ /$out_str/, "$mname($in_str): STDERR contains >> \"$out_str\""); >> + ok($app->buffer() !~ /$out_str/, "$mname($in_str): Buffer does NOT >> contain \"$out_str\""); >> +} >> + >> + >> ok(1, "Initialized OK"); >> ############################################################ >> @@ -94,13 +105,12 @@ >> >> $log->level($OFF); # $OFF == $FATAL... although I suspect that's a >> bug in the log4j spec >> >> -foreach my $f ("logwarn", "logcarp", "logcluck", >> - "error_warn", "error_die") { >> +foreach my $f ("logwarn", "logcarp", "logcluck", "error_warn") { >> warndietest_nooutput(sub {$log->$f(@_)}, "Test $test: $f", "Test >> $test: $f", $app, "$f"); >> $test++; >> } >> >> -foreach my $f ("logdie", "logcroak", "logconfess") { >> - warndietest(sub {$log->$f(@_)}, "Test $test: $f", "Test $test: >> $f", $app, "$f"); >> +foreach my $f ("error_die", "logdie", "logcroak", "logconfess") { >> + dietest_nooutput(sub {$log->$f(@_)}, "Test $test: $f", "Test >> $test: $f", $app, "$f"); >> $test++; >> } >> Index: t/025CustLevels.t >> =================================================================== >> RCS file: /cvsroot/log4perl/Log-Log4perl/t/025CustLevels.t,v >> retrieving revision 1.1 >> diff -a -u -r1.1 025CustLevels.t >> --- t/025CustLevels.t 3 Sep 2002 18:09:42 -0000 1.1 >> +++ t/025CustLevels.t 9 Sep 2002 02:11:26 -0000 >> @@ -1,6 +1,7 @@ >> ########################################### >> # Test Suite for Log::Log4perl::Config >> -# Mike Schilli, 2002 (m...@pe...) >> +# Erik Selberg, (c) 2002 er...@se... >> +# clone of 025CustLevels.t but uses nicer method (?) we hope >> ########################################### >> >> ######################### >> @@ -9,26 +10,61 @@ >> use Test; >> >> #create a custom level "LITEWARN" >> -BEGIN { >> -package Log::Log4perl::Level; >> -our %PRIORITY = ( >> - "FATAL" => 0, >> - "ERROR" => 3, >> - "WARN" => 4, >> - "LITEWARN" => 5, >> - "INFO" => 6, >> - "DEBUG" => 7, >> -); >> -} >> - >> - >> use Log::Log4perl; >> use Log::Log4perl::Level; >> use Log::Log4perl::TestBuffer; >> +# use strict; >> >> >> ok(1); # If we made it this far, we're ok. >> >> +Log::Log4perl::Logger::create_custom_level("LITEWARN", "WARN"); >> + >> +# test insane creation of levels >> + >> +foreach (1 .. 14) { >> + ok(Log::Log4perl::Logger::create_custom_level("TEST$_", "INFO"), 0); >> +} >> + >> +# 15th should fail.. this assumes that each level is 10000 apart from >> +# the other. >> + >> +ok(eval { Log::Log4perl::Logger::create_custom_level("TEST15", >> "INFO") }, + undef); >> + >> +# now, by re-arranging (as we whine about in create_custom_levels), we >> +# should be able to get 15. >> + >> +my %btree = ( >> + 8 => "DEBUG", >> + 4 => 8, >> + 2 => 4, >> + 1 => 2, >> + 3 => 4, >> + 6 => 8, >> + 5 => 6, >> + 7 => 8, >> + 12 => "DEBUG", >> + 10 => 12, >> + 9 => 10, >> + 11 => 12, >> + 14 => "DEBUG", >> + 13 => 14, >> + 15 => "DEBUG", >> + ); >> + >> +foreach (8, 4, 2, 1, 3, 6, 5, 7, 12, 10, 9, 11, 14, 13, 15) { >> + my $level = $btree{$_} eq "DEBUG" ? "DEBUG" : "BTREE$btree{$_}"; >> +# warn("Creating BTREE$_ after $level"); >> + ok(Log::Log4perl::Logger::create_custom_level("BTREE$_", $level), 0); >> +# warn("BTREE$_ is ", ${Log::Log4perl::Level::PRIORITY{"BTREE$_"}}); >> +} >> + >> +# foreach (1 .. 15) { >> +# warn("BTREE$_ is: ", >> ${Log::Log4perl::Level::PRIORITY{"BTREE$_"}}); >> +# } >> + >> + >> my $LOGFILE = "example.log"; >> unlink $LOGFILE; >> >> @@ -40,10 +76,16 @@ >> EOT >> >> >> - >> Log::Log4perl::init(\$config); >> >> >> +# can't create a custom level after init... let's test that. Just look >> +# for an undef (i.e. failure) from the eval >> + >> +ok(eval { Log::Log4perl::Logger::create_custom_level("NOTIFY", >> "WARN"); }, >> + undef); >> + >> + >> # ********************* >> # check a category logger >> >> @@ -76,6 +118,7 @@ >> >> $logger->log($WARN, "a warning message"); >> $logger->log($LITEWARN, "a LITE warning message"); >> +die("lame hack to suppress warning") if ($LITEWARN != $LITEWARN); >> $logger->log($DEBUG, "an info message, should not log"); >> >> open FILE, "<$LOGFILE" or die "Cannot open $LOGFILE"; >> @@ -92,9 +135,12 @@ >> ok(! $logger->is_info); >> >> >> +# warn("Testing inc_level()"); >> + >> #*************************** >> #increase/decrease leves >> -$logger->inc_level(); #bump up from litewarn to warn >> +$logger->inc_level(1); #bump up from litewarn to warn >> +# warn("level is now: ", $logger->level()); >> ok($logger->is_warn); >> ok(!$logger->is_litewarn); >> ok(!$logger->is_info); >> @@ -107,14 +153,15 @@ >> my $result4 = "WARN - after bumping, warning message\n"; >> ok($data, "$result1$result2$result3$result4"); >> >> - >> $logger->dec_level(2); #bump down from warn to litewarn to info >> + >> ok($logger->is_warn); >> ok($logger->is_litewarn); >> ok($logger->is_info); >> + >> ok(! $logger->is_debug) ; >> >> >> -BEGIN { plan tests => 15 }; >> +BEGIN { plan tests => 46 }; >> >> unlink $LOGFILE; >> >> > > > |
From: <msc...@ao...> - 2002-09-09 06:28:38
|
FYI ... -- Mike Mike Schilli log...@pe... http://perlmeister.com |
From: <msc...@ao...> - 2002-09-09 06:27:14
|
> Maybe Mozilla is doing weird stuff... anyway, I > re-confirmed that the patch works. But to make life > easy, I put it up on my website. Interesting. Can you confirm the patch works even after you send mail to yourself? Anyway, the patch on your website worked (yay!) like a charm. Couple of questions/requests on your changes: * Looks like the error message here got garbeled (Logger.pm): my $after = shift || die("create_custom_level: forgot to pass in an after string! * What's the purpose of our %PRIORITY = (); # unless (%PRIORITY); our %LEVELS = () unless (%LEVELS); our %SYSLOG = () unless (%SYSLOG); And why the '#' in the first line? * Documentation: Can you add a couple of lines to Log::Log4perl.pm to show how to use the custom level features? * Why the logic # figure out new int value by AFTER + (AFTER+ 1) / 2 if you could just store the priorities defined so far orderly in an array and switch to the next/previous element? * # This is a bit better way to create code on the fly than eval'ing strings. # -erik Nice. Does this mean they're (-d) debuggable now? Could we go all the way and use this in set_output_methods() as well? Looks like your foreach loop is outside the subroutine and therefore only called when the module is loaded: #now lets autogenerate the logger subs based on the defined priorities foreach my $level (keys %Log::Log4perl::Level::PRIORITY){ create_log_level_methods($level); } Would be great if you could shed some light on these issues ... :) -- Mike Mike Schilli log...@pe... http://perlmeister.com |
From: <msc...@ao...> - 2002-09-08 19:09:07
|
Hi md...@ji..., thanks for your patch -- but it's already implemented in the pending 0.23 release, currently only available via CVS. It implements the standard log4j %d{} formats as documented in http://jakarta.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html which are somewhat different from strftime. Also, ABSOLUTE, DATE, and ISO8601 are supported. Please check out the version from CVS and let me know if it fits your needs. If you have trouble using CVS, let me know, I can send you a tarball. -- Mike Mike Schilli log...@pe... http://perlmeister.com |
From: Mark B. <md...@ji...> - 2002-09-08 18:17:09
|
Hi. I noticed in Log::Log4perl::Layout::PatternLayout the comment, # TODO: 'd', 't', 'x', 'X' # lib4j PatternLayout as documented in # http://jakarta.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html Is anyone currently working in this area? In particular, is "%d{}" support in the CVS tree (I only have release 0.22 at my disposal now). I took a quick hack at it (context diff is appended). It basically adds in the dedicated data formatters, For better results it is recommended to use the log4j date formatters. These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifying AbsoluteTimeDateFormat, DateTimeDateFormat and respectively ISO8601DateFormat. For example, %d{ISO8601} or %d{ABSOLUTE}. and uses strftime(3) formatting otherwise. If (a) nobody is currently working on this; and (b) this approach is acceptable I can make a proper diff with test cases, more error handling and some documentation. But I didn't want to devote a lot fo time to this if either (a) or (b) are untrue. Thanks. -- -mb- ======================================== *** PatternLayout.pm.orig Sat Jul 20 12:16:36 2002 --- PatternLayout.pm Sun Sep 8 11:15:37 2002 *************** *** 132,143 **** $info{r} = int((tv_interval ( $PROGRAM_START_TIME ))*1000); if($self->{info_needed}->{d}) { ! my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = ! localtime(time); ! $info{d} = sprintf "%d/%02d/%02d %02d:%02d:%02d", ! $year + 1900, $mon+1, $mday, ! $hour, $min, $sec; } # As long as they're not implemented yet .. --- 132,144 ---- $info{r} = int((tv_interval ( $PROGRAM_START_TIME ))*1000); if($self->{info_needed}->{d}) { ! # Formats a Date in the format "YYYY-mm-dd HH:mm:ss,SSS" for example ! # "1999-11-27 15:49:37,459". [default format if no curlies] ! my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = ! localtime(time); ! $info{d} = sprintf "%04d-%02d-%02d %02d:%02d:%02d", ! $year + 1900, $mon+1, $mday, $hour, $min, $sec; } # As long as they're not implemented yet .. *************** *** 170,175 **** --- 171,178 ---- $data = shrink_category($data, $curlies); } elsif($ops eq "C") { $data = shrink_category($data, $curlies); + } elsif($ops eq "d") { + $data = format_time($data, $curlies); } return $data; *************** *** 188,193 **** --- 191,241 ---- } return $category; + } + + ################################################## + sub format_time { + ################################################## + use POSIX qw(strftime mktime); + + my($time, $fmt) = @_; + + my $date_time = "N/A"; + + if ($fmt =~ /ISO8601/) { + $date_time = $time; # default (already formatted) + } elsif ($time =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/) { + my ($year,$mon,$mday,$hour,$min,$sec) = ($1,$2,$3,$4,$5,$6); + if ($fmt =~ /ABSOLUTE/) { + # Formats a Date in the format "HH:mm:ss,SSS" for example, + # "15:49:37,459". + + $date_time = sprintf "%02d:%02d:%02d", $hour, $min, $sec; + + } elsif ($fmt =~ /DATE/) { + # Formats a Date in the format "dd MMM YYYY HH:mm:ss,SSS" for example, + # "06 Nov 1994 15:49:37,459". + + $date_time = sprintf "%02d %3s %04d %02d:%02d:%02d", + $mday, + ( qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) )[$mon-1], + $year, $hour, $min, $sec; + } else { + # simple strftime(3) formatting for now + ### TODO: SimpleDateFormat support: + # http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html + + my $time = mktime($sec,$min,$hour-1,$mday,$mon-1,$year-1900); + $date_time = strftime($fmt, localtime($time)); + + } + + } else { + warn "INTERNAL ERROR"; + + } + + return $date_time; } 1; |
From: Kevin G. <ke...@go...> - 2002-09-08 03:58:27
|
> How about we split the difference and just have inc_level / dec_level > AND more_logging / less_logging? Tee hee--perfect! "Erik W. Selberg" wrote: > > So I understand that inc_level / more_logging may not increase the > amount of messages for lots of reasons. appender threshholds being a > fine one. appenders that send those levels to random places being > another. Lack of logging messages at that level being a third. :) But I > don't think that matters so much. > > How about we split the difference and just have inc_level / dec_level > AND more_logging / less_logging? Not like we can't make functions > aliases for the other. This way, folks who like to think of incrementing > and decrementing levels can, and folks who just want more or less > logging can just call the obvious function. > > -e > > Kevin Goess wrote: > > > > I'm confused... can you give me an example whereby changing the logging > > > from WARN to INFO would result in FEWER messages? > > > > You're absolutely right, there's not, I was confused, thinking of > > appender thresholds. However, there is the easy case where changing a > > logger level from WARN to INFO would not result in any change in > > logging behavior: > > log4perl.appender.app1.Threshold = WARN > > in which case neither INFO nor DEBUG messages ever appear in that > > appender's logs. See attached for a non-contrived example. > > > > I'm perfectly happy to be outvoted, shall we have a chorus of AYE's or > > NAY's for > > > > inc_level/dec_level more_logging/less_logging pumpup/silence other? > > > > > > Erik W. Selberg wrote: > > > >> Kevin Goess wrote: > >> > >>> Jeez, don't you guys sleep? > >> > >> > >> > >> um..... no. :p > >> > >>> After thinking about this for a day, I have to say I'm convinced > >>> inc_level and dec_level best describe what's going on. > >>> more/less_logging or pumpup/silence both presuppose that changing a > >>> logger's level towards DEBUG results in *more* messages. That's not > >>> necessarily the case, with appender thresholds it might just result > >>> in *different* message behavior, maybe even less messages? What the > >>> functions are doing is changing the level, what logging behavior > >>> that change results in is up to the config file. > >> > >> > >> > >> I'm confused... can you give me an example whereby changing the > >> logging from WARN to INFO would result in FEWER messages? To the > >> below, there is an intrinsic ordering, and my take away is that a > >> higher level in the ordering will spew out (a) all the log messages > >> of the previous levels, and (b) all the log messages of the current > >> level. > >> > >> Granted, you COULD do something like: > >> > >> if ($logger->is_warn()) { $logger->warn("This only shows up when > >> we're at WARN level"); } > >> > >> but nobody's gonna do that, really. > >> > >> -e > >> > >>> > >>> What inc_level and dec_level do is change the level of the logger. > >>> Since the log4j docs say quite prominently: > >>> > >>> "Basic Selection Rule: A log request of level p in a logger with > >>> (either assigned or inherited, whichever is appropriate) level q, is > >>> enabled if p >= q. > >>> This rule is at the heart of log4j. It assumes that levels are > >>> ordered. For the standard levels, we have DEBUG < INFO < WARN < > >>> ERROR < FATAL. " > >>> > >>> I understand your motivation in saying "the less I like exposing the > >>> user to the concept that there's some integer value that corresponds > >>> to a Level" but that's not the same as saying we shouldn't expose > >>> the user to the concept that levels are ordered and are > >>> comparisonable, which is a basic fact of life in log4j. > >>> > >>> If we really wanted to do it cleanly, we'd have a Priority.pm object > >>> with is_greater and is_less_than methods, like log4j does and we'd > >>> throw those around instead of the integers, but that would be stupid > >>> performance-wise and I think we don't want to go there yet, right? > >>> > >>> BTW, there's also a getSyslogEquivalent() in Priority.java, so > >>> that's fair game to implement. > >>> > >>> And re you guys' confusion between these proposed functions going in > >>> Level.pm vs. Logger.pm, note that my implementation has > >>> Logger::inc_level() calling Level::get_higher_level() to get the > >>> right value. > >>> > >>> > >>> Erik W. Selberg wrote: > >>> > >>>> Why would these be part of the Level class? I'd imagine they'd be > >>>> part of the Logger class and affect the Logger's current Level. > >>>> > >>>> -e > >>>> > >>>> > >>>> msc...@ao... wrote: > >>>> > >>>>> In a message dated Tue, 3 Sep 2002 9:50:57 PM Eastern Standard > >>>>> Time, er...@se... writes: > >>>>> > >>>>> > >>>>> > >>>>>> So the more I think about it, the less I like exposing the user > >>>>>> to the concept that there's some integer value that corresponds > >>>>>> to a Level > >>>>>> > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> > >>>>> Good point. Only problem is that more_logging/less_logging methods > >>>>> are kinda strange in a "Level" class. How about pumpup() and > >>>>> silence() :) ? > >>>>> > >>>>> -- Mike > >>>>> > >>>>> Mike Schilli > >>>>> log...@pe... > >>>>> http://perlmeister.com > >>>>> > >>>>> > >>>>> ------------------------------------------------------- > >>>>> This sf.net email is sponsored by: OSDN - Tired of that same old > >>>>> cell phone? Get a new here for FREE! > >>>>> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > >>>>> _______________________________________________ > >>>>> log4perl-devel mailing list > >>>>> log...@li... > >>>>> https://lists.sourceforge.net/lists/listinfo/log4perl-devel > >>>>> > >>>>> > >>>>> > >>>> > >>>> > >>>> > >>>> > >>>> > >>>> ------------------------------------------------------- > >>>> This sf.net email is sponsored by: OSDN - Tired of that same old > >>>> cell phone? Get a new here for FREE! > >>>> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > >>>> _______________________________________________ > >>>> log4perl-devel mailing list > >>>> log...@li... > >>>> https://lists.sourceforge.net/lists/listinfo/log4perl-devel > >>> > >>> > >>> > >>> > >>> > >> > >> > >> > > > > > >------------------------------------------------------------------------ > > > >#!/usr/bin/perl > > > >use Log::Log4perl; > > > >my $config = <<EOT; > > > >log4perl.category.app = FATAL, pageTheVP > >log4perl.category.app.module1 = INFO, applicationLogs > > > >log4perl.appender.pageTheVP = Log::Dispatch::Screen > >log4perl.appender.pageTheVP.layout = Log::Log4perl::Layout::SimpleLayout > >log4perl.appender.pageTheVP.Threshold = FATAL > > > >log4perl.appender.applicationLogs = Log::Log4perl::TestBuffer > >log4perl.appender.applicationLogs.layout = Log::Log4perl::Layout::SimpleLayout > > > >EOT > > > >Log::Log4perl::init(\$config); > > > >my $logger = Log::Log4perl::get_logger('app.module1'); > > > > > >$logger->info('info message 1'); > >$logger->info('info message 2'); > >$logger->info('info message 3'); > >$logger->inc_level(); > >$logger->debug('debug message'); > >$logger->fatal('big problem!!!'); > > > > > > > > > > -- Happy Trails . . . Kevin M. Goess (and Anne and Frank) 904 Carmel Ave. Albany, CA 94706 (510) 525-5217 |
From: <Msc...@ao...> - 2002-09-07 19:15:42
|
In a message dated 9/6/02 7:34:38 PM W. Europe Daylight Time, ke...@go... writes: > I'm perfectly happy to be outvoted, shall we have a chorus of AYE's or > NAY's for > > inc_level/dec_level more_logging/less_logging pumpup/silence other? > I'm fine either way, I'll let you guys haggle it out :) -- Mike Mike Schilli log...@pe... http://perlmeister.com |
From: Erik W. S. <er...@se...> - 2002-09-07 10:24:07
|
So I understand that inc_level / more_logging may not increase the amount of messages for lots of reasons. appender threshholds being a fine one. appenders that send those levels to random places being another. Lack of logging messages at that level being a third. :) But I don't think that matters so much. How about we split the difference and just have inc_level / dec_level AND more_logging / less_logging? Not like we can't make functions aliases for the other. This way, folks who like to think of incrementing and decrementing levels can, and folks who just want more or less logging can just call the obvious function. -e Kevin Goess wrote: > > I'm confused... can you give me an example whereby changing the logging > > from WARN to INFO would result in FEWER messages? > > You're absolutely right, there's not, I was confused, thinking of > appender thresholds. However, there is the easy case where changing a > logger level from WARN to INFO would not result in any change in > logging behavior: > log4perl.appender.app1.Threshold = WARN > in which case neither INFO nor DEBUG messages ever appear in that > appender's logs. See attached for a non-contrived example. > > I'm perfectly happy to be outvoted, shall we have a chorus of AYE's or > NAY's for > > inc_level/dec_level more_logging/less_logging pumpup/silence other? > > > Erik W. Selberg wrote: > >> Kevin Goess wrote: >> >>> Jeez, don't you guys sleep? >> >> >> >> um..... no. :p >> >>> After thinking about this for a day, I have to say I'm convinced >>> inc_level and dec_level best describe what's going on. >>> more/less_logging or pumpup/silence both presuppose that changing a >>> logger's level towards DEBUG results in *more* messages. That's not >>> necessarily the case, with appender thresholds it might just result >>> in *different* message behavior, maybe even less messages? What the >>> functions are doing is changing the level, what logging behavior >>> that change results in is up to the config file. >> >> >> >> I'm confused... can you give me an example whereby changing the >> logging from WARN to INFO would result in FEWER messages? To the >> below, there is an intrinsic ordering, and my take away is that a >> higher level in the ordering will spew out (a) all the log messages >> of the previous levels, and (b) all the log messages of the current >> level. >> >> Granted, you COULD do something like: >> >> if ($logger->is_warn()) { $logger->warn("This only shows up when >> we're at WARN level"); } >> >> but nobody's gonna do that, really. >> >> -e >> >>> >>> What inc_level and dec_level do is change the level of the logger. >>> Since the log4j docs say quite prominently: >>> >>> "Basic Selection Rule: A log request of level p in a logger with >>> (either assigned or inherited, whichever is appropriate) level q, is >>> enabled if p >= q. >>> This rule is at the heart of log4j. It assumes that levels are >>> ordered. For the standard levels, we have DEBUG < INFO < WARN < >>> ERROR < FATAL. " >>> >>> I understand your motivation in saying "the less I like exposing the >>> user to the concept that there's some integer value that corresponds >>> to a Level" but that's not the same as saying we shouldn't expose >>> the user to the concept that levels are ordered and are >>> comparisonable, which is a basic fact of life in log4j. >>> >>> If we really wanted to do it cleanly, we'd have a Priority.pm object >>> with is_greater and is_less_than methods, like log4j does and we'd >>> throw those around instead of the integers, but that would be stupid >>> performance-wise and I think we don't want to go there yet, right? >>> >>> BTW, there's also a getSyslogEquivalent() in Priority.java, so >>> that's fair game to implement. >>> >>> And re you guys' confusion between these proposed functions going in >>> Level.pm vs. Logger.pm, note that my implementation has >>> Logger::inc_level() calling Level::get_higher_level() to get the >>> right value. >>> >>> >>> Erik W. Selberg wrote: >>> >>>> Why would these be part of the Level class? I'd imagine they'd be >>>> part of the Logger class and affect the Logger's current Level. >>>> >>>> -e >>>> >>>> >>>> msc...@ao... wrote: >>>> >>>>> In a message dated Tue, 3 Sep 2002 9:50:57 PM Eastern Standard >>>>> Time, er...@se... writes: >>>>> >>>>> >>>>> >>>>>> So the more I think about it, the less I like exposing the user >>>>>> to the concept that there's some integer value that corresponds >>>>>> to a Level >>>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> Good point. Only problem is that more_logging/less_logging methods >>>>> are kinda strange in a "Level" class. How about pumpup() and >>>>> silence() :) ? >>>>> >>>>> -- Mike >>>>> >>>>> Mike Schilli >>>>> log...@pe... >>>>> http://perlmeister.com >>>>> >>>>> >>>>> ------------------------------------------------------- >>>>> This sf.net email is sponsored by: OSDN - Tired of that same old >>>>> cell phone? Get a new here for FREE! >>>>> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >>>>> _______________________________________________ >>>>> log4perl-devel mailing list >>>>> log...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/log4perl-devel >>>>> >>>>> >>>>> >>>> >>>> >>>> >>>> >>>> >>>> ------------------------------------------------------- >>>> This sf.net email is sponsored by: OSDN - Tired of that same old >>>> cell phone? Get a new here for FREE! >>>> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >>>> _______________________________________________ >>>> log4perl-devel mailing list >>>> log...@li... >>>> https://lists.sourceforge.net/lists/listinfo/log4perl-devel >>> >>> >>> >>> >>> >> >> >> > > >------------------------------------------------------------------------ > >#!/usr/bin/perl > >use Log::Log4perl; > >my $config = <<EOT; > >log4perl.category.app = FATAL, pageTheVP >log4perl.category.app.module1 = INFO, applicationLogs > >log4perl.appender.pageTheVP = Log::Dispatch::Screen >log4perl.appender.pageTheVP.layout = Log::Log4perl::Layout::SimpleLayout >log4perl.appender.pageTheVP.Threshold = FATAL > >log4perl.appender.applicationLogs = Log::Log4perl::TestBuffer >log4perl.appender.applicationLogs.layout = Log::Log4perl::Layout::SimpleLayout > >EOT > >Log::Log4perl::init(\$config); > >my $logger = Log::Log4perl::get_logger('app.module1'); > > >$logger->info('info message 1'); >$logger->info('info message 2'); >$logger->info('info message 3'); >$logger->inc_level(); >$logger->debug('debug message'); >$logger->fatal('big problem!!!'); > > > > > |
From: Erik W. S. <er...@se...> - 2002-09-07 10:20:12
|
Enjoy. Changes for this one: 1. FOO_INT now use the same integer value from log4j (although they're not exported... yet :). 2. Rather than go through some convoluded mapping to get things in the order we want, I reversed a couple greater than / less thans, so the order goes the way we want. Still somewhat hard to grok, but if you write things like: DEBUG > INFO > WARN > ERROR > FATAL it starts to make sense. Kinda. 3. Added check (and test) to make sure create_custom_level is called before init(). 4. Created test that cust_prio doesn't already exist. FYI, if you do the following: foreach (1 .. 15) { create_custom_level("FOO$_", "DEBUG"); } it'll fail at 15. So I made a blurb that roughly describes how to allocate things manually in a binary tree style to get 15 levels between two. Still don't think anyone will go there, but who knows. Also put in a test for both cases. :) What I didn't do: - I left create_custom_level in Logger for the time being. I wanted to get the rest into CVS before I start that, as it wasn't as trivial as I thought to move. Cheers, -e Msc...@ao... wrote: > In a message dated 9/5/02 8:28:12 PM Pacific Daylight Time, > er...@se... writes: > > >> Did one of you guys check in the patch? I'll make the above changes, >> just wanted to know from which repository to work from. :) > > > > Haven't integrated it yet -- please feel free to work off the current > CVS. > > -- Mike |
From: Kevin G. <ke...@go...> - 2002-09-06 17:17:25
|
> I'm confused... can you give me an example whereby changing the logging > from WARN to INFO would result in FEWER messages? You're absolutely right, there's not, I was confused, thinking of appender thresholds. However, there is the easy case where changing a logger level from WARN to INFO would not result in any change in logging behavior: log4perl.appender.app1.Threshold = WARN in which case neither INFO nor DEBUG messages ever appear in that appender's logs. See attached for a non-contrived example. I'm perfectly happy to be outvoted, shall we have a chorus of AYE's or NAY's for inc_level/dec_level more_logging/less_logging pumpup/silence other? Erik W. Selberg wrote: > Kevin Goess wrote: > >> Jeez, don't you guys sleep? > > > um..... no. :p > >> After thinking about this for a day, I have to say I'm convinced >> inc_level and dec_level best describe what's going on. >> more/less_logging or pumpup/silence both presuppose that changing a >> logger's level towards DEBUG results in *more* messages. That's not >> necessarily the case, with appender thresholds it might just result in >> *different* message behavior, maybe even less messages? What the >> functions are doing is changing the level, what logging behavior that >> change results in is up to the config file. > > > I'm confused... can you give me an example whereby changing the logging > from WARN to INFO would result in FEWER messages? To the below, there is > an intrinsic ordering, and my take away is that a higher level in the > ordering will spew out (a) all the log messages of the previous levels, > and (b) all the log messages of the current level. > > Granted, you COULD do something like: > > if ($logger->is_warn()) { $logger->warn("This only shows up when we're > at WARN level"); } > > but nobody's gonna do that, really. > > -e > >> >> What inc_level and dec_level do is change the level of the logger. >> Since the log4j docs say quite prominently: >> >> "Basic Selection Rule: A log request of level p in a logger with >> (either assigned or inherited, whichever is appropriate) level q, is >> enabled if p >= q. >> This rule is at the heart of log4j. It assumes that levels are >> ordered. For the standard levels, we have DEBUG < INFO < WARN < ERROR >> < FATAL. " >> >> I understand your motivation in saying "the less I like exposing the >> user to the concept that there's some integer value that corresponds >> to a Level" but that's not the same as saying we shouldn't expose the >> user to the concept that levels are ordered and are comparisonable, >> which is a basic fact of life in log4j. >> >> If we really wanted to do it cleanly, we'd have a Priority.pm object >> with is_greater and is_less_than methods, like log4j does and we'd >> throw those around instead of the integers, but that would be stupid >> performance-wise and I think we don't want to go there yet, right? >> >> BTW, there's also a getSyslogEquivalent() in Priority.java, so that's >> fair game to implement. >> >> And re you guys' confusion between these proposed functions going in >> Level.pm vs. Logger.pm, note that my implementation has >> Logger::inc_level() calling Level::get_higher_level() to get the right >> value. >> >> >> Erik W. Selberg wrote: >> >>> Why would these be part of the Level class? I'd imagine they'd be >>> part of the Logger class and affect the Logger's current Level. >>> >>> -e >>> >>> >>> msc...@ao... wrote: >>> >>>> In a message dated Tue, 3 Sep 2002 9:50:57 PM Eastern Standard Time, >>>> er...@se... writes: >>>> >>>> >>>> >>>>> So the more I think about it, the less I like exposing the user to >>>>> the concept that there's some integer value that corresponds to a >>>>> Level >>>>> >>>> >>>> >>>> >>>> >>>> Good point. Only problem is that more_logging/less_logging methods >>>> are kinda strange in a "Level" class. How about pumpup() and >>>> silence() :) ? >>>> >>>> -- Mike >>>> >>>> Mike Schilli >>>> log...@pe... >>>> http://perlmeister.com >>>> >>>> >>>> ------------------------------------------------------- >>>> This sf.net email is sponsored by: OSDN - Tired of that same old >>>> cell phone? Get a new here for FREE! >>>> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >>>> _______________________________________________ >>>> log4perl-devel mailing list >>>> log...@li... >>>> https://lists.sourceforge.net/lists/listinfo/log4perl-devel >>>> >>>> >>>> >>> >>> >>> >>> >>> >>> ------------------------------------------------------- >>> This sf.net email is sponsored by: OSDN - Tired of that same old >>> cell phone? Get a new here for FREE! >>> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >>> _______________________________________________ >>> log4perl-devel mailing list >>> log...@li... >>> https://lists.sourceforge.net/lists/listinfo/log4perl-devel >> >> >> >> > > > -- Happy Trails . . . Kevin M. Goess (and Anne and Frank) 904 Carmel Ave. Albany, CA 94706 (510) 525-5217 |
From: <Msc...@ao...> - 2002-09-06 03:32:46
|
In a message dated 9/5/02 8:28:12 PM Pacific Daylight Time, er...@se... writes: > Did one of you guys check in the patch? I'll make the above changes, > just wanted to know from which repository to work from. :) > Haven't integrated it yet -- please feel free to work off the current CVS. -- Mike |
From: Erik W. S. <er...@se...> - 2002-09-06 03:27:56
|
Kevin Goess wrote: > Nice work, a couple of questions: > > 1) Why are you reversing the order of the PRIORITY int's from log4j > "these are actually REVERSED from log4j'cuz it makes our life > easier."? How so, it's an arbitrary internal ordering, isn't it? > While I understand that if it's arbitrary and internal then it doesn't > matter, I think we should do our part to fight entropy by keeping > unnecessary divergence to a minimun. So, in reality, the only place those constants (FOO_INT) are used is to populate the add_prioritiy() calls a bit later... they aren't exported at all. So only their name comes from log4j. What we could do is set those constants to be what log4j has and then have some other hash table that does the conversion from a descending order to an acending one. > > 2) I agree that my suggested BEGIN block is not the way to do it, but > I'm worried about create_custom_level(). If they call it after the > engine has seen init(), it could result in undefined behavior. Could > we just disallow it if $INITIALIZED is already set? Yeah, that make sense to me. > > 3) create_custom_level() should really be in Level.pm not Logger.pm, > don't you think? And the interface to calling it could actually be in > Log4perl.pm, a pass-thru. Hmmm... yeah, I'd buy that. I'd also buy create_log_level_methods moving there too. > > 4) For my own education, can you explain the rationale behind "This is > a bit better way to create code on the fly than eval'ing strings." I > understand that it may be faster, but in this case I can see > advantages to the string eval in that you don't have to turn off > strict refs, it catches cases where the user tries to name a level > like WARN-LITE (where "warn-lite" is not a valid perl subroutine name, > otherwise the error isn't caught until the user tries to call > $log->warn-lite(..)), and in this case I think the intent of the code > reads more clearly as an eval'd string. So my own knowledge is > deficient--I can't see where the improvement is. There are a couple, although your point above is well-taken. The primary (pragmatic) one is that I was having a devil of a time implementing a function as the (main package) variable $WARNLIGHT (or whatever I tried to use) is not imported in the eval. I'm still not clear on the cause, but the chat whores in #perl suggested that there was a known issue with variable scoping and eval'ing to create subroutines, and I was better off to use the code template / closure method (which is what I did). The other two reasons which if I didn't hit the problem above I'd have ignored are: (a) eval'ing is slower compared with creating the code refs (b) the code refs are created at Perl compile time, which means if I go in and hack the code and put in a typo, Perl catches it. If it's a string and I fat-finger sometihng, you don't see that until the eval. To your point, perhaps a check beforehand to make sure that $lclevel conforms to Perl function name conventions and dies with a descriptive error? > 5) my $cust_prio = int(($priority{$after} + $next_prio) / 2); > Just to be complete, we should check that they haven't added so many > priorities that we've run out of halves and are stepping on existing > numbers, shouldn't we? Oh, sure. Although whomever makes the 10,000 levels between two we give 'em deserves what he or she gets, IMHO. :) Did one of you guys check in the patch? I'll make the above changes, just wanted to know from which repository to work from. :) -e > > Erik W. Selberg wrote: > >> Actually, ignore my previous patch and check this one out. I took the >> liberty of re-doing how the code is generated using the following syntax: >> >> *{ <foo> } = sub { <bar> } >> >> vs: >> >> $code = "sub foo { <bar> }"; eval $code; >> >> which enabled me to re-use it to auto-create new levels on the fly >> using: >> >> Log::Log4perl::Logger::create_custom_level("LITEWARN", "WARN"); >> >> I also re-did 025CustLevels.t with this in mind, as I think it's >> nicer than the BEGIN block method. >> >> While I was at it, I also updated logdie and friends so they die >> regardless of the OFF setting (and changed appropriate test classes), >> and implemented the newer constants that Mike has (although note I'm >> pretty sure this patch will clobber his). >> >> Cheers, >> -e >> >> >> >> ------------------------------------------------------- >> This sf.net email is sponsored by: OSDN - Tired of that same old >> cell phone? Get a new here for FREE! >> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >> _______________________________________________ >> log4perl-devel mailing list >> log...@li... >> https://lists.sourceforge.net/lists/listinfo/log4perl-devel > > > |
From: Erik W. S. <er...@se...> - 2002-09-06 03:01:57
|
Kevin Goess wrote: > Jeez, don't you guys sleep? um..... no. :p > After thinking about this for a day, I have to say I'm convinced > inc_level and dec_level best describe what's going on. > more/less_logging or pumpup/silence both presuppose that changing a > logger's level towards DEBUG results in *more* messages. That's not > necessarily the case, with appender thresholds it might just result in > *different* message behavior, maybe even less messages? What the > functions are doing is changing the level, what logging behavior that > change results in is up to the config file. I'm confused... can you give me an example whereby changing the logging from WARN to INFO would result in FEWER messages? To the below, there is an intrinsic ordering, and my take away is that a higher level in the ordering will spew out (a) all the log messages of the previous levels, and (b) all the log messages of the current level. Granted, you COULD do something like: if ($logger->is_warn()) { $logger->warn("This only shows up when we're at WARN level"); } but nobody's gonna do that, really. -e > > What inc_level and dec_level do is change the level of the logger. > Since the log4j docs say quite prominently: > > "Basic Selection Rule: A log request of level p in a logger with > (either assigned or inherited, whichever is appropriate) level q, is > enabled if p >= q. > This rule is at the heart of log4j. It assumes that levels are > ordered. For the standard levels, we have DEBUG < INFO < WARN < ERROR > < FATAL. " > > I understand your motivation in saying "the less I like exposing the > user to the concept that there's some integer value that corresponds > to a Level" but that's not the same as saying we shouldn't expose the > user to the concept that levels are ordered and are comparisonable, > which is a basic fact of life in log4j. > > If we really wanted to do it cleanly, we'd have a Priority.pm object > with is_greater and is_less_than methods, like log4j does and we'd > throw those around instead of the integers, but that would be stupid > performance-wise and I think we don't want to go there yet, right? > > BTW, there's also a getSyslogEquivalent() in Priority.java, so that's > fair game to implement. > > And re you guys' confusion between these proposed functions going in > Level.pm vs. Logger.pm, note that my implementation has > Logger::inc_level() calling Level::get_higher_level() to get the right > value. > > > Erik W. Selberg wrote: > >> Why would these be part of the Level class? I'd imagine they'd be >> part of the Logger class and affect the Logger's current Level. >> >> -e >> >> >> msc...@ao... wrote: >> >>> In a message dated Tue, 3 Sep 2002 9:50:57 PM Eastern Standard Time, >>> er...@se... writes: >>> >>> >>> >>>> So the more I think about it, the less I like exposing the user to >>>> the concept that there's some integer value that corresponds to a Level >>>> >>> >>> >>> >>> Good point. Only problem is that more_logging/less_logging methods >>> are kinda strange in a "Level" class. How about pumpup() and >>> silence() :) ? >>> >>> -- Mike >>> >>> Mike Schilli >>> log...@pe... >>> http://perlmeister.com >>> >>> >>> ------------------------------------------------------- >>> This sf.net email is sponsored by: OSDN - Tired of that same old >>> cell phone? Get a new here for FREE! >>> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >>> _______________________________________________ >>> log4perl-devel mailing list >>> log...@li... >>> https://lists.sourceforge.net/lists/listinfo/log4perl-devel >>> >>> >>> >> >> >> >> >> >> ------------------------------------------------------- >> This sf.net email is sponsored by: OSDN - Tired of that same old >> cell phone? Get a new here for FREE! >> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >> _______________________________________________ >> log4perl-devel mailing list >> log...@li... >> https://lists.sourceforge.net/lists/listinfo/log4perl-devel > > > |
From: <Msc...@ao...> - 2002-09-05 17:38:08
|
In a message dated 9/3/02 11:23:26 AM Pacific Daylight Time, ke...@go... writes: > It's all in CVS, see the new unit test 025CustLevels.t . Any comments? > Oops, haven't responded yet, I like the quick-and-dirty approach, gets the job done. Let's see if Erik comes up with something else, if so, we can integrate that. -- Mike Mike Schilli msc...@ao... AOL Screen Name Service |
From: Kevin G. <ke...@go...> - 2002-09-05 16:58:17
|
Nice work, a couple of questions: 1) Why are you reversing the order of the PRIORITY int's from log4j "these are actually REVERSED from log4j'cuz it makes our life easier."? How so, it's an arbitrary internal ordering, isn't it? While I understand that if it's arbitrary and internal then it doesn't matter, I think we should do our part to fight entropy by keeping unnecessary divergence to a minimun. 2) I agree that my suggested BEGIN block is not the way to do it, but I'm worried about create_custom_level(). If they call it after the engine has seen init(), it could result in undefined behavior. Could we just disallow it if $INITIALIZED is already set? 3) create_custom_level() should really be in Level.pm not Logger.pm, don't you think? And the interface to calling it could actually be in Log4perl.pm, a pass-thru. 4) For my own education, can you explain the rationale behind "This is a bit better way to create code on the fly than eval'ing strings." I understand that it may be faster, but in this case I can see advantages to the string eval in that you don't have to turn off strict refs, it catches cases where the user tries to name a level like WARN-LITE (where "warn-lite" is not a valid perl subroutine name, otherwise the error isn't caught until the user tries to call $log->warn-lite(..)), and in this case I think the intent of the code reads more clearly as an eval'd string. So my own knowledge is deficient--I can't see where the improvement is. 5) my $cust_prio = int(($priority{$after} + $next_prio) / 2); Just to be complete, we should check that they haven't added so many priorities that we've run out of halves and are stepping on existing numbers, shouldn't we? Erik W. Selberg wrote: > Actually, ignore my previous patch and check this one out. I took the > liberty of re-doing how the code is generated using the following syntax: > > *{ <foo> } = sub { <bar> } > > vs: > > $code = "sub foo { <bar> }"; eval $code; > > which enabled me to re-use it to auto-create new levels on the fly using: > > Log::Log4perl::Logger::create_custom_level("LITEWARN", "WARN"); > > I also re-did 025CustLevels.t with this in mind, as I think it's nicer > than the BEGIN block method. > > While I was at it, I also updated logdie and friends so they die > regardless of the OFF setting (and changed appropriate test classes), > and implemented the newer constants that Mike has (although note I'm > pretty sure this patch will clobber his). > > Cheers, > -e > > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > log4perl-devel mailing list > log...@li... > https://lists.sourceforge.net/lists/listinfo/log4perl-devel -- Happy Trails . . . Kevin M. Goess (and Anne and Frank) 904 Carmel Ave. Albany, CA 94706 (510) 525-5217 |
From: Kevin G. <ke...@go...> - 2002-09-05 16:21:06
|
Jeez, don't you guys sleep? After thinking about this for a day, I have to say I'm convinced inc_level and dec_level best describe what's going on. more/less_logging or pumpup/silence both presuppose that changing a logger's level towards DEBUG results in *more* messages. That's not necessarily the case, with appender thresholds it might just result in *different* message behavior, maybe even less messages? What the functions are doing is changing the level, what logging behavior that change results in is up to the config file. What inc_level and dec_level do is change the level of the logger. Since the log4j docs say quite prominently: "Basic Selection Rule: A log request of level p in a logger with (either assigned or inherited, whichever is appropriate) level q, is enabled if p >= q. This rule is at the heart of log4j. It assumes that levels are ordered. For the standard levels, we have DEBUG < INFO < WARN < ERROR < FATAL. " I understand your motivation in saying "the less I like exposing the user to the concept that there's some integer value that corresponds to a Level" but that's not the same as saying we shouldn't expose the user to the concept that levels are ordered and are comparisonable, which is a basic fact of life in log4j. If we really wanted to do it cleanly, we'd have a Priority.pm object with is_greater and is_less_than methods, like log4j does and we'd throw those around instead of the integers, but that would be stupid performance-wise and I think we don't want to go there yet, right? BTW, there's also a getSyslogEquivalent() in Priority.java, so that's fair game to implement. And re you guys' confusion between these proposed functions going in Level.pm vs. Logger.pm, note that my implementation has Logger::inc_level() calling Level::get_higher_level() to get the right value. Erik W. Selberg wrote: > Why would these be part of the Level class? I'd imagine they'd be part > of the Logger class and affect the Logger's current Level. > > -e > > > msc...@ao... wrote: > >> In a message dated Tue, 3 Sep 2002 9:50:57 PM Eastern Standard Time, >> er...@se... writes: >> >> >> >>> So the more I think about it, the less I like exposing the user to >>> the concept that there's some integer value that corresponds to a Level >>> >> >> >> Good point. Only problem is that more_logging/less_logging methods are >> kinda strange in a "Level" class. How about pumpup() and silence() :) ? >> >> -- Mike >> >> Mike Schilli >> log...@pe... >> http://perlmeister.com >> >> >> ------------------------------------------------------- >> This sf.net email is sponsored by: OSDN - Tired of that same old >> cell phone? Get a new here for FREE! >> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >> _______________________________________________ >> log4perl-devel mailing list >> log...@li... >> https://lists.sourceforge.net/lists/listinfo/log4perl-devel >> >> >> > > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > log4perl-devel mailing list > log...@li... > https://lists.sourceforge.net/lists/listinfo/log4perl-devel -- Happy Trails . . . Kevin M. Goess (and Anne and Frank) 904 Carmel Ave. Albany, CA 94706 (510) 525-5217 |
From: Erik W. S. <er...@se...> - 2002-09-05 07:02:11
|
Why would these be part of the Level class? I'd imagine they'd be part of the Logger class and affect the Logger's current Level. -e msc...@ao... wrote: >In a message dated Tue, 3 Sep 2002 9:50:57 PM Eastern Standard Time, er...@se... writes: > > > >>So the more I think about it, the less I like exposing the user to the >>concept that there's some integer value that corresponds to a Level >> >> > >Good point. Only problem is that more_logging/less_logging methods are kinda strange in a "Level" class. How about pumpup() and silence() :) ? > >-- Mike > >Mike Schilli >log...@pe... >http://perlmeister.com > > >------------------------------------------------------- >This sf.net email is sponsored by: OSDN - Tired of that same old >cell phone? Get a new here for FREE! >https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >_______________________________________________ >log4perl-devel mailing list >log...@li... >https://lists.sourceforge.net/lists/listinfo/log4perl-devel > > > |
From: <msc...@ao...> - 2002-09-05 06:58:14
|
In a message dated Tue, 3 Sep 2002 9:50:57 PM Eastern Standard Time, er...@se... writes: >So the more I think about it, the less I like exposing the user to the >concept that there's some integer value that corresponds to a Level Good point. Only problem is that more_logging/less_logging methods are kinda strange in a "Level" class. How about pumpup() and silence() :) ? -- Mike Mike Schilli log...@pe... http://perlmeister.com |
From: Erik W. S. <er...@se...> - 2002-09-05 06:53:38
|
Sorry bout that (although it's a bit moot). One of CVS's major drawbacks: patch management. :/ -e msc...@ao... wrote: >>So, I got a different patch, that does the same stuff >>only more. >> >> > >Sorry, I can't apply your patch. It contains backed-up Emacs files, CVS directories, and it's not in a format my "patch" can process. Could you please submit it again, using the standard > > cvs diff -Nau > >while you're located in the Log-Log4perl directory? Also, please make sure there's none of your local files left. If you want to make sure it's actually working, just check out a fresh version of Log-Log4perl, apply your patch and check the result. This way you're making it easier for me to get your stuff in. > >-- Mike > >Mike Schilli >log...@pe... >http://perlmeister.com > > > >------------------------------------------------------- >This sf.net email is sponsored by: OSDN - Tired of that same old >cell phone? Get a new here for FREE! >https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >_______________________________________________ >log4perl-devel mailing list >log...@li... >https://lists.sourceforge.net/lists/listinfo/log4perl-devel > > > |
From: Erik W. S. <er...@se...> - 2002-09-05 06:43:50
|
oh yeah, the patch. :) -e |