| 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 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | 9 | ▶ | sub new{ | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 9 | my($class, $options) = @_; | |||||||||||||||||||||||||||
| 36 | my $self = { | ||||||||||||||||||||||||||||
| 37 | 9 | '__debug' => $options->{'debug'} | |||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||
| 39 | 9 | bless $self, $class; | |||||||||||||||||||||||||||
| 40 | 9 | 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 | 8 | ▶ | sub log{ #a simple way to log a message to the apache error log | ||||||||||||||||||||||||||
|
Subroutine
log: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 8 | my($self, $message, $severity) = @_; | |||||||||||||||||||||||||||
| 57 | 8 | ▶ | $severity = "" unless $severity; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 8 | ▶ | return if !$self->{'__debug'} and $severity eq 'debug'; #ignore debug messages when not in debug mode | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->{"__debug"} and $severity eq "debug"
MC/DC100%2/2
not $self->{"__debug"} and $severity eq "debug"
not $self->{"__debug"}
$severity eq "debug"
Truth table100%3/3
not(A) and B
A= not $self->{"__debug"}B= $severity eq "debug"
| |||||||||||||||||||||||||||||
| 59 | 7 | print STDERR uc($severity) . " - " . $message . "\n"; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | ################################################# | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head1 Notes | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 Author | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | MacGyveR <dumb@cpan.org> | ||||||||||||||||||||||||||||
| 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 | 6 | return 1; | |||||||||||||||||||||||||||