[Jifty-commit] r2839 - in jifty/trunk: lib/Jifty
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sun Feb 25 16:36:13 EST 2007
Author: falcone
Date: Sun Feb 25 16:36:13 2007
New Revision: 2839
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Logger.pm
Log:
r16889 at ketch: falcone | 2007-02-25 16:33:57 -0500
* DBD::pg passes postgres' warnings up, so try to convert their various
logging levels back to Log4Perl levels.
Completely heuristic, probably wants more guarding so it doesn't
reach out and bite someone.
* This quiets some of the most annoting warns revealed when I removed
the log-level downing in Script/Schema.pm
Modified: jifty/trunk/lib/Jifty/Logger.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Logger.pm (original)
+++ jifty/trunk/lib/Jifty/Logger.pm Sun Feb 25 16:36:13 2007
@@ -118,10 +118,11 @@
# If the logger has been taken apart by global destruction,
# don't try to use it to log warnings
if (Log::Log4perl->initialized) {
+ my $action = $self->_warning_action(@_);
# @_ often has read-only scalars, so we need to break
# the aliasing so we can remove trailing newlines
my @lines = map {"$_"} @_;
- $logger->warn(map {chomp; $_} @lines);
+ $logger->$action(map {chomp; $_} @lines);
}
elsif ($previous_warning_handler) {
# Fallback to the old handler
@@ -162,6 +163,44 @@
}
}
+=head2 _warning_action
+
+change the Log4Perl action from warn to error|info|etc based
+on the content of the warning.
+
+Added because DBD::Pg throws up NOTICE and other messages
+as warns, and we really want those to be info (or error, depending
+on the code). List based on Postgres documentation
+
+TODO: needs to be smarter than just string matching
+
+returns a valid Log::Log4Perl action, if nothing matches
+will return the default of warn since we're in a __WARN__ handler
+
+=cut
+
+sub _warning_action {
+ my $self = shift;
+ my $warnings = join('', at _);
+
+ my %pg_notices = ('DEBUG\d+' => 'debug',
+ 'INFO' => 'info',
+ 'NOTICE' => 'info',
+ 'WARNING' => 'warn',
+ 'DBD::Pg.+ERROR' => 'error',
+ 'LOG' => 'warn',
+ 'FATAL' => 'fatal',
+ 'PANIC' => 'fatal' );
+
+ foreach my $notice (keys %pg_notices) {
+ if ($warnings =~ /^$notice:/) {
+ return $pg_notices{$notice};
+ }
+ }
+
+ return 'warn';
+}
+
=head1 AUTHOR
Various folks at Best Practical Solutions, LLC.
More information about the Jifty-commit
mailing list