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 2 2 100.0
total 27 27 100.0


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   84380 use strict;
  6         17  
  6         145  
18 6     6   24 use warnings;
  6         8  
  6         840  
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 1 794 my($class, $options) = @_;
36             my $self = {
37 9         29 '__debug' => $options->{'debug'}
38             };
39 9         22 bless $self, $class;
40 9         18 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 8     8 1 5110 my($self, $message, $severity) = @_;
57 8 100       18 $severity = "" unless $severity;
58 8 100 100     43 return if !$self->{'__debug'} and $severity eq 'debug'; #ignore debug messages when not in debug mode
59 7         225 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) 2019 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;