[Bps-public-commit] r13202 - in Shipwright/trunk: .
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Thu Jun 12 10:16:42 EDT 2008
Author: sunnavy
Date: Thu Jun 12 10:16:24 2008
New Revision: 13202
Modified:
Shipwright/trunk/ (props changed)
Shipwright/trunk/lib/Shipwright/Logger.pm
Log:
r13311 at sunnavys-mb: sunnavy | 2008-06-12 21:45:00 +0800
refactor Logger.pm, init should not rely on Shipwright object, it can be fed any stuff that has log_level and log_file info
Modified: Shipwright/trunk/lib/Shipwright/Logger.pm
==============================================================================
--- Shipwright/trunk/lib/Shipwright/Logger.pm (original)
+++ Shipwright/trunk/lib/Shipwright/Logger.pm Thu Jun 12 10:16:24 2008
@@ -3,6 +3,7 @@
use warnings;
use Carp;
use Log::Log4perl;
+use Scalar::Util qw/blessed/;
=head2 new
@@ -10,28 +11,49 @@
sub new {
my $class = shift;
- my $shipwright = shift;
my $self = {};
bless $self, $class;
if ( not Log::Log4perl->initialized ) {
- $class->_initialize_log4perl($shipwright);
+ $class->_initialize_log4perl(@_);
}
return $self;
}
sub _initialize_log4perl {
- my $class = shift;
- my $shipwright = shift;
+ my $class = shift;
+ my $ref = $_[0];
+
+ my ( $log_level, $log_file );
+
+ if ( blessed $ref ) {
+
+ # so it's an object, we assuming it has log_level and log_file subs
+ $log_level = $ref->log_level;
+ $log_file = $ref->log_file;
+ }
+ elsif ( ref $ref ) {
+
+ # it's a hashref
+ $log_level = $ref->{log_level};
+ $log_file = $ref->{log_file};
+ }
+ else {
+
+ # not ref at all
+ my %hash = @_;
+ $log_level = $hash{log_level};
+ $log_file = $hash{log_file};
+ }
- my $log_level = uc $shipwright->log_level || 'ERROR';
+ $log_level = uc $log_level || 'ERROR';
my %default;
- if ( $shipwright->log_file ) {
+ if ($log_file) {
%default = (
'log4perl.rootLogger' => "$log_level,File",
- 'log4perl.appender.File.filename' => $shipwright->log_file,
+ 'log4perl.appender.File.filename' => $log_file,
'log4perl.appender.File' => 'Log::Log4perl::Appender::File',
'log4perl.appender.File.stderr' => 1,
'log4perl.appender.File.layout' =>
More information about the Bps-public-commit
mailing list