File Coverage

blib/lib/Log/Cabin/Foundation.pm
Criterion Covered Total %
statement 12 60 20.0
branch 0 14 0.0
condition 0 33 0.0
subroutine 4 21 19.0
pod 0 17 0.0
total 16 145 11.0


line stmt bran cond sub pod time code
1             package Log::Cabin::Foundation;
2              
3 1     1   4 use strict;
  1         2  
  1         29  
4 1     1   4 use warnings;
  1         1  
  1         34  
5              
6             require Exporter;
7 1     1   6 use AutoLoader qw(AUTOLOAD);
  1         1  
  1         7  
8              
9             our @ISA = qw(Exporter);
10              
11             # Items to export into callers namespace by default. Note: do not export
12             # names by default without a very good reason. Use EXPORT_OK instead.
13             # Do not simply export all your public functions/methods/constants.
14              
15             # This allows declaration use Log::Cabin::Foundation ':all';
16             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
17             # will save memory.
18             our %EXPORT_TAGS = ( 'all' => [ qw(
19            
20             ) ] );
21              
22             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
23              
24             our @EXPORT = qw(
25            
26             );
27              
28             our $VERSION = '0.06';
29              
30              
31             # Preloaded methods go here.
32              
33 1     1   92 use strict;
  1         2  
  1         799  
34              
35             my $OFF=0;
36             my $FATAL=1;
37             my $ERROR=2;
38             my $WARN=3;
39             my $INFO=4;
40             my $DEBUG=5;
41             my $ALL=6;
42              
43             sub new {
44 0     0 0   my $class = shift;
45              
46             #This singleton is an instance of Log::Cabin This singleton is
47             #required to have all multiple logger instances write to the same
48             #log files with access to the global logger settings
49 0           my $loggersingleton = shift;
50 0           my $name = shift;
51              
52 0   0       my $self = bless {}, ref($class) || $class;
53              
54 0 0         $name = 'default' if (!defined $name);
55 0           $self->{_name} = $name;
56              
57 0 0         die if(!defined $loggersingleton);
58 0           $self->set_logger_instance($loggersingleton);
59 0           $self->{_LOG_LEVEL} = $self->level();
60              
61 0           return $self;
62             }
63              
64             sub name {
65 0     0 0   return $_[0]->{_name};
66             }
67              
68             sub set_logger_instance{
69 0     0 0   my($self,$instance) = @_;
70 0           $self->{_logsimpleobj} = $instance;
71             }
72              
73             sub fatal{
74 0     0 0   my($self,$msg) = @_;
75 0 0 0       if($self->{_LOG_LEVEL} >= $FATAL || $self->{_logsimpleobj}->{_LOG_LEVEL} >= $FATAL){
76 0           $self->{_logsimpleobj}->_output($msg,$self->{_name},$FATAL,caller(0));
77             }
78             }
79              
80             sub error{
81 0     0 0   my($self,$msg) = @_;
82 0 0 0       if($self->{_LOG_LEVEL} >= $ERROR || $self->{_logsimpleobj}->{_LOG_LEVEL} >= $ERROR){
83 0           $self->{_logsimpleobj}->_output($msg,$self->{_name},$ERROR,caller(0));
84             }
85             }
86              
87             sub warn{
88 0     0 0   my($self,$msg) = @_;
89 0 0 0       if($self->{_LOG_LEVEL} >= $WARN || $self->{_logsimpleobj}->{_LOG_LEVEL} >= $WARN){
90 0           $self->{_logsimpleobj}->_output($msg,$self->{_name},$WARN,caller(0));
91             }
92             }
93              
94             sub info{
95 0     0 0   my($self,$msg) = @_;
96 0 0 0       if($self->{_LOG_LEVEL} >= $INFO || $self->{_logsimpleobj}->{_LOG_LEVEL} >= $INFO){
97 0           $self->{_logsimpleobj}->_output($msg,$self->{_name},$INFO,caller(0));
98             }
99             }
100              
101             sub debug{
102 0     0 0   my($self,$msg) = @_;
103 0 0 0       if($self->{_LOG_LEVEL} >= $DEBUG || $self->{_logsimpleobj}->{_LOG_LEVEL} >= $DEBUG){
104 0           $self->{_logsimpleobj}->_output($msg,$self->{_name},$DEBUG,caller(0));
105             }
106             }
107              
108             sub logdie{
109 0     0 0   my($self,$msg) = @_;
110 0           $self->{_logsimpleobj}->_output($msg,$self->{_name},$FATAL,caller(0));
111 0           my($package,$filename,$line,$subroutine) = caller(0);
112 0           die "Died with '$msg' at $filename line $line\n";
113             }
114              
115             sub is_fatal{
116 0     0 0   my $self = shift;
117 0   0       return ($self->{_LOG_LEVEL} >= $FATAL) || ($self->{_logsimpleobj}->{_LOG_LEVEL} >= $FATAL);
118             }
119             sub is_error{
120 0     0 0   my $self = shift;
121 0   0       return ($self->{_LOG_LEVEL} >= $ERROR) || ($self->{_logsimpleobj}->{_LOG_LEVEL} >= $ERROR);
122             }
123             sub is_warn{
124 0     0 0   my $self = shift;
125 0   0       return ($self->{_LOG_LEVEL} >= $WARN) || ($self->{_logsimpleobj}->{_LOG_LEVEL} >= $WARN);
126             }
127             sub is_info{
128 0     0 0   my $self = shift;
129 0   0       return ($self->{_LOG_LEVEL} >= $INFO) || ($self->{_logsimpleobj}->{_LOG_LEVEL} >= $INFO);
130             }
131             sub is_debug{
132 0     0 0   my $self = shift;
133 0   0       return ($self->{_LOG_LEVEL} >= $DEBUG) || ($self->{_logsimpleobj}->{_LOG_LEVEL} >= $DEBUG);
134             }
135              
136             #
137             #Set log levels for named logger
138             #These log levels will be overridden by the global log level set in the singleton instance of
139             #Log::Cabin
140              
141             sub level {
142 0     0 0   my($self,$level) = @_;
143 0           $self->{_logsimpleobj}->level($level);
144             }
145              
146             sub more_logging{
147 0     0 0   my($self,$level) = @_;
148 0           $self->{_LOG_LEVEL} += $level;
149             }
150              
151             sub less_logging{
152 0     0 0   my($self,$level) = @_;
153 0           $self->{_LOG_LEVEL} -= $level;
154             }
155              
156             # Autoload methods go after =cut, and are processed by the autosplit program.
157              
158             1;
159             __END__