| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Binance::API::Logger; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # MIT License | 
| 4 |  |  |  |  |  |  | # | 
| 5 |  |  |  |  |  |  | # Copyright (c) 2017 Lari Taskula | 
| 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 |  |  | 3 |  | 98546 | use strict; | 
|  | 3 |  |  |  |  | 18 |  | 
|  | 3 |  |  |  |  | 108 |  | 
| 26 | 3 |  |  | 3 |  | 19 | use warnings; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 91 |  | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 3 |  |  | 3 |  | 17 | use Carp; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 242 |  | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 3 |  |  | 3 |  | 1482 | use Binance::Constants qw( :all ); | 
|  | 3 |  |  |  |  | 10 |  | 
|  | 3 |  |  |  |  | 1288 |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =head1 NAME | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | Binance::API::Logger -- Logger for L | 
| 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 object. | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | B | 
| 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 | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | A C object. | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =cut | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | sub new { | 
| 77 | 5 |  |  | 5 | 1 | 6027 | my $class = shift; | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 5 |  |  |  |  | 16 | my $self = { | 
| 80 |  |  |  |  |  |  | logger => undef, | 
| 81 |  |  |  |  |  |  | }; | 
| 82 |  |  |  |  |  |  |  | 
| 83 | 5 | 100 |  |  |  | 22 | $self->{logger} = shift if @_; | 
| 84 |  |  |  |  |  |  |  | 
| 85 | 5 |  |  |  |  | 25 | bless $self, $class; | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | sub AUTOLOAD { | 
| 89 | 56 |  |  | 56 |  | 3955 | my $self = shift; | 
| 90 |  |  |  |  |  |  |  | 
| 91 | 56 |  |  |  |  | 92 | my $level = our $AUTOLOAD; | 
| 92 | 56 |  |  |  |  | 291 | $level =~ s/.*://; | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 56 | 100 |  |  |  | 304 | return if $level eq 'DESTROY'; | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 51 |  | 50 |  |  | 125 | my $message = shift || ""; | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 51 |  |  |  |  | 196 | my $sub = (caller(1))[3]; | 
| 99 | 51 |  |  |  |  | 1090 | my $full_message = "[$sub] ". $message; | 
| 100 |  |  |  |  |  |  |  | 
| 101 | 51 | 100 | 66 |  |  | 219 | if ($level eq 'debug' || $level eq 'trace') { | 
| 102 | 14 |  |  |  |  | 23 | carp $full_message if DEBUG; | 
| 103 |  |  |  |  |  |  | } else { | 
| 104 | 37 |  |  |  |  | 369 | carp $full_message; | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 | 51 | 50 | 33 |  |  | 12277 | if ($self->{logger} && $self->{logger}->can($level)) { | 
| 108 | 0 |  |  |  |  |  | $self->{logger}->$level($full_message); | 
| 109 |  |  |  |  |  |  | } | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | 1; |