| 1 | package Binance::API::Logger; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # MIT License | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # Copyright (c) 2017 Lari Taskula <lari@taskula.fi> | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||||||||||||||||||||||||
| 8 | # of this software and associated documentation files (the "Software"), to deal | ||||||||||||||||||||||||||||
| 9 | # in the Software without restriction, including without limitation the rights | ||||||||||||||||||||||||||||
| 10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||||||||||||||||||||||||
| 11 | # copies of the Software, and to permit persons to whom the Software is | ||||||||||||||||||||||||||||
| 12 | # furnished to do so, subject to the following conditions: | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | # The above copyright notice and this permission notice shall be included in all | ||||||||||||||||||||||||||||
| 15 | # copies or substantial portions of the Software. | ||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||
| 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||||||||||||||||||||||||
| 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||||||||||||||||||||||||
| 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||||||||||||||||||||||||
| 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||||||||||||||||||||||||
| 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||||||||||||||||||||||||
| 22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||||||||||||||||||||||||
| 23 | # SOFTWARE. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 3 | ▶ | use Binance::Constants qw( :all ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 NAME | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | Binance::API::Logger -- Logger for L<Binance::API> | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | Provides a wrapper for your desired logger. Carps log calls higher than "debug" | ||||||||||||||||||||||||||||
| 39 | level | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | use Binance::API; | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | my $logger = Binance::API::Logger->new($log4perl); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | $logger->warn("This is a warning"); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head1 METHODS | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head2 new | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | my $logger = Binance::API::Logger->new($log4perl); | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Instantiates a new C<Binance::API::Logger> object. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | B<PARAMETERS> | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =over | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =item A logger object that implements (at least) debug, warn, | ||||||||||||||||||||||||||||
| 64 | error, fatal level logging. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | [OPTIONAL] | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =back | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | B<RETURNS> | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | A C<Binance::API::Logger> object. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub new { | ||||||||||||||||||||||||||||
| 77 | 5 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 5 | my $self = { | |||||||||||||||||||||||||||
| 80 | logger => undef, | ||||||||||||||||||||||||||||
| 81 | }; | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 5 | ▶ | $self->{logger} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 5 | bless $self, $class; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | sub AUTOLOAD { | ||||||||||||||||||||||||||||
| 89 | 56 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=7 SCAR=20.3
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 56 | my $level = our $AUTOLOAD; | |||||||||||||||||||||||||||
| 92 | 56 | $level =~ s/.*://; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 56 | ▶ | return if $level eq 'DESTROY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 51 | ▶ | my $message = shift || ""; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 51 | my $sub = (caller(1))[3]; | |||||||||||||||||||||||||||
| 99 | 51 | my $full_message = "[$sub] ". $message; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 51 | ▶ | if ($level eq 'debug' || $level eq 'trace') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$level eq "debug" or $level eq "trace"
MC/DC50%1/2
$level eq "debug" or $level eq "trace"
$level eq "debug"
$level eq "trace"
Truth table66%2/3
A or B
A= $level eq "debug"B= $level eq "trace"
| |||||||||||||||||||||||||||||
| 102 | 14 | carp $full_message if DEBUG; | |||||||||||||||||||||||||||
| 103 | } else { | ||||||||||||||||||||||||||||
| 104 | 37 | carp $full_message; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 51 | ▶ | if ($self->{logger} && $self->{logger}->can($level)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"logger"} and $self->{"logger"}->can($level)
MC/DC0%0/2
$self->{"logger"} and $self->{"logger"}->can($level)
$self->{"logger"}
$self->{"logger"}->can($level)
Truth table33%1/3
A and B
A= $self->{"logger"}B= $self->{"logger"}->can($level)
| |||||||||||||||||||||||||||||
| 108 | 0 | $self->{logger}->$level($full_message); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 3 | 1; | |||||||||||||||||||||||||||