File Coverage

lib/PSGI/Hector/Log.pm
Criterion Covered Total %
statement 14 14 100.0
branch 4 4 100.0
condition 3 3 100.0
subroutine 4 4 100.0
pod 1 2 50.0
total 26 27 96.3


line stmt bran cond sub pod time code
1             package PSGI::Hector::Log;
2              
3             =pod
4              
5             =head1 NAME
6              
7             PSGI::Hector::Log - Logging class
8              
9             =head1 SYNOPSIS
10              
11             =head1 DESCRIPTION
12              
13             =head1 METHODS
14              
15             =cut
16              
17 6     6   104643 use strict;
  6         21  
  6         172  
18 6     6   27 use warnings;
  6         10  
  6         1016  
19             #########################################################
20              
21             =pod
22              
23             #head2 new($options)
24              
25             $log = PSGI::Hector::Log->new({
26             'debug' => 1
27             });
28              
29             Creates a new instance of the logging class
30              
31             =cut
32              
33             #########################################################
34             sub new{
35 9     9 0 1307 my($class, $options) = @_;
36             my $self = {
37 9         50 '__debug' => $options->{'debug'}
38             };
39 9         22 bless $self, $class;
40 9         23 return $self;
41             }
42             #########################################################
43              
44             =pod
45              
46             =head2 log($message, $severity)
47              
48             $log->log('Just testing', 'info');
49              
50             Logs the provided string to STDERR with a prefixed severity.
51              
52             =cut
53              
54             ###########################################################
55             sub log{ #a simple way to log a message to the apache error log
56 6     6 1 6664 my($self, $message, $severity) = @_;
57 6 100       19 $severity = "" unless $severity;
58 6 100 100     40 return if !$self->{'__debug'} and $severity eq 'debug'; #ignore debug messages when not in debug mode
59 5         231 print STDERR uc($severity) . " - " . $message . "\n";
60             }
61             #################################################
62              
63             =head1 Notes
64              
65             =head1 Author
66              
67             MacGyveR
68              
69             Development questions, bug reports, and patches are welcome to the above address.
70              
71             =head1 See Also
72              
73             =head1 Copyright
74              
75             Copyright (c) 2017 MacGyveR. All rights reserved.
76              
77             This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
78              
79             =cut
80              
81             ###############################################
82             return 1;