Index: lib/Catalyst.pm =================================================================== --- lib/Catalyst.pm (revision 8185) +++ lib/Catalyst.pm (working copy) @@ -239,8 +239,10 @@ =head2 -Log -Specifies log level. + use Catalyst '-Log=warn,fatal,error'; +Specifies a comma-delimited list of log levels. + =head2 -Stats Enables statistics collection and reporting. You can also force this setting @@ -2168,19 +2170,33 @@ =head2 $c->setup_log -Sets up log. +Sets up log by instantiating a L object and +passing it to C. Pass in a comma-delimited list of levels to set the +log to. +This method also installs a C method that returns a true value into the +catalyst subclass if the "debug" level is passed in the comma-delimited list, +or if the C<$CATALYST_DEBUG> environment variable is set to a true value. + +Note that if the log has already been setup, by either a previous call to +C or by a call such as C<< __PACKAGE__->log( MyLogger->new ) >>, +that this method won't actually set up the log. + =cut sub setup_log { - my ( $class, $debug ) = @_; + my ( $class, $levels ) = @_; + $levels =~ s/^\s+//; + $levels =~ s/\s+$//; + my %levels = map { $_ => 1 } split /\s*,\s*/, $levels || ''; + unless ( $class->log ) { - $class->log( Catalyst::Log->new ); + $class->log( Catalyst::Log->new( keys %levels) ); } my $env_debug = Catalyst::Utils::env_value( $class, 'DEBUG' ); - if ( defined($env_debug) ? $env_debug : $debug ) { + if (defined $env_debug or $levels{debug} ) { no strict 'refs'; *{"$class\::debug"} = sub { 1 }; $class->log->debug('Debug messages enabled');