| 1 | package OpenInteract2::Log; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # $Id: Log.pm,v 1.8 2005/03/18 04:09:48 lachoy Exp $ | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 87 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 87 | ▶ | use base qw( Exporter ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 87 | ▶ | use Log::Log4perl qw( :levels get_logger ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 87 | ▶ | use Log::Log4perl::Appender; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 87 | @OpenInteract2::Log::EXPORT_OK = qw( uchk ); | |||||||||||||||||||
| 11 | 87 | $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 | 0 | ▶ | sub uchk { | ||||||||||||||||||
|
Subroutine
uchk: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 19 | 0 | my ( $msg, @args ) = @_; | |||||||||||||||||||
| 20 | 0 | ▶ | return sprintf( $msg, map { ( defined $_ ) ? $_ : '' } @args ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 87 | my $DEFAULT_LEVEL = $WARN; | |||||||||||||||||||
| 24 | 87 | my $DEFAULT_CONF_FILE = 'log4perl.conf'; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | sub init_from_website { | ||||||||||||||||||
|
Subroutine
init_from_website: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 27 | 0 | my ( $class, $website_dir ) = @_; | |||||||||||||||||||
| 28 | 0 | ▶ | if ( -d $website_dir ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 87 | ▶ | sub init_file { | ||||||||||||||||||
|
Subroutine
init_file: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||
| 40 | 87 | my ( $class, $file, $level ) = @_; | |||||||||||||||||||
| 41 | 87 | ▶ | unless ( $file ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | return $class->init_screen( $level ); | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | 87 | my $appender = Log::Log4perl::Appender->new( | |||||||||||||||||||
| 45 | 'Log::Log4perl::Appender::File', | ||||||||||||||||||||
| 46 | filename => $file, | ||||||||||||||||||||
| 47 | mode => 'append', | ||||||||||||||||||||
| 48 | autoflush => 1 ); | ||||||||||||||||||||
| 49 | 87 | return $class->_create_with_appender( $appender, $level ); | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | sub init_screen { | ||||||||||||||||||
|
Subroutine
init_screen: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 53 | 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 | 87 | ▶ | sub _create_with_appender { | ||||||||||||||||||
|
Subroutine
_create_with_appender: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 61 | 87 | my ( $class, $appender, $level ) = @_; | |||||||||||||||||||
| 62 | 87 | ▶ | $level ||= $DEFAULT_LEVEL; | ||||||||||||||||||
|
Condition33%1/3
$level ||= $DEFAULT_LEVEL
MC/DC0%0/2
$level ||= $DEFAULT_LEVEL
$level
$DEFAULT_LEVEL
Truth table33%1/3
A ||= B
A= $levelB= $DEFAULT_LEVEL
| |||||||||||||||||||||
| 63 | 87 | $appender->layout( $class->_get_default_layout() ); | |||||||||||||||||||
| 64 | 87 | my $log = Log::Log4perl->get_logger( '' ); | |||||||||||||||||||
| 65 | 87 | $log->level( $level ); | |||||||||||||||||||
| 66 | 87 | $log->add_appender( $appender ); | |||||||||||||||||||
| 67 | 87 | return $log; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 87 | ▶ | sub _get_default_layout { | ||||||||||||||||||
|
Subroutine
_get_default_layout: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 71 | 87 | require Log::Log4perl::Layout::PatternLayout; | |||||||||||||||||||
| 72 | 87 | return Log::Log4perl::Layout::PatternLayout->new( "%d{HH:mm:ss} %p %c %C (%L) %m %n"); | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 87 | 1; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||