| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package OpenInteract2::Log; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Log.pm,v 1.8 2005/03/18 04:09:48 lachoy Exp $ |
|
4
|
|
|
|
|
|
|
|
|
5
|
85
|
|
|
85
|
|
499
|
use strict; |
|
|
85
|
|
|
|
|
163
|
|
|
|
85
|
|
|
|
|
4185
|
|
|
6
|
85
|
|
|
85
|
|
445
|
use base qw( Exporter ); |
|
|
85
|
|
|
|
|
161
|
|
|
|
85
|
|
|
|
|
7177
|
|
|
7
|
85
|
|
|
85
|
|
488
|
use Log::Log4perl qw( :levels get_logger ); |
|
|
85
|
|
|
|
|
193
|
|
|
|
85
|
|
|
|
|
814
|
|
|
8
|
85
|
|
|
85
|
|
10521
|
use Log::Log4perl::Appender; |
|
|
85
|
|
|
|
|
210
|
|
|
|
85
|
|
|
|
|
55233
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
@OpenInteract2::Log::EXPORT_OK = qw( uchk ); |
|
11
|
|
|
|
|
|
|
$OpenInteract2::Log::VERSION = sprintf("%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Create a logging message by treating the first argument as a sprintf |
|
15
|
|
|
|
|
|
|
# string and the remainder of the arguments as the parameters to set, |
|
16
|
|
|
|
|
|
|
# each of which will be undef-tested before processing |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub uchk { |
|
19
|
0
|
|
|
0
|
0
|
|
my ( $msg, @args ) = @_; |
|
20
|
0
|
0
|
|
|
|
|
return sprintf( $msg, map { ( defined $_ ) ? $_ : '' } @args ); |
|
|
0
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $DEFAULT_LEVEL = $WARN; |
|
24
|
|
|
|
|
|
|
my $DEFAULT_CONF_FILE = 'log4perl.conf'; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub init_from_website { |
|
27
|
0
|
|
|
0
|
0
|
|
my ( $class, $website_dir ) = @_; |
|
28
|
0
|
0
|
|
|
|
|
if ( -d $website_dir ) { |
|
29
|
0
|
|
|
|
|
|
my $conf_file = File::Spec->catfile( |
|
30
|
|
|
|
|
|
|
$website_dir, 'conf', $DEFAULT_CONF_FILE ); |
|
31
|
0
|
|
|
|
|
|
Log::Log4perl::init( $conf_file ); |
|
32
|
0
|
|
|
|
|
|
return get_logger(); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
else { |
|
35
|
0
|
|
|
|
|
|
return $class->init_screen; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub init_file { |
|
40
|
0
|
|
|
0
|
0
|
|
my ( $class, $file, $level ) = @_; |
|
41
|
0
|
0
|
|
|
|
|
unless ( $file ) { |
|
42
|
0
|
|
|
|
|
|
return $class->init_screen( $level ); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
0
|
|
|
|
|
|
my $appender = Log::Log4perl::Appender->new( |
|
45
|
|
|
|
|
|
|
'Log::Log4perl::Appender::File', |
|
46
|
|
|
|
|
|
|
filename => $file, |
|
47
|
|
|
|
|
|
|
mode => 'append', |
|
48
|
|
|
|
|
|
|
autoflush => 1 ); |
|
49
|
0
|
|
|
|
|
|
return $class->_create_with_appender( $appender, $level ); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub init_screen { |
|
53
|
0
|
|
|
0
|
0
|
|
my ( $class, $level ) = @_; |
|
54
|
0
|
|
|
|
|
|
my $appender = Log::Log4perl::Appender->new( |
|
55
|
|
|
|
|
|
|
'Log::Log4perl::Appender::Screen' ); |
|
56
|
0
|
|
|
|
|
|
return $class->_create_with_appender( $appender, $level ); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _create_with_appender { |
|
61
|
0
|
|
|
0
|
|
|
my ( $class, $appender, $level ) = @_; |
|
62
|
0
|
|
0
|
|
|
|
$level ||= $DEFAULT_LEVEL; |
|
63
|
0
|
|
|
|
|
|
$appender->layout( $class->_get_default_layout() ); |
|
64
|
0
|
|
|
|
|
|
my $log = Log::Log4perl->get_logger( '' ); |
|
65
|
0
|
|
|
|
|
|
$log->level( $level ); |
|
66
|
0
|
|
|
|
|
|
$log->add_appender( $appender ); |
|
67
|
0
|
|
|
|
|
|
return $log; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _get_default_layout { |
|
71
|
0
|
|
|
0
|
|
|
require Log::Log4perl::Layout::PatternLayout; |
|
72
|
0
|
|
|
|
|
|
return Log::Log4perl::Layout::PatternLayout->new( "%d{HH:mm:ss} %p %c %C (%L) %m %n"); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |