line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::EventStreamr::Roles::Logger; |
2
|
|
|
|
|
|
|
|
3
|
16
|
|
|
16
|
|
159290
|
use Log::Log4perl; |
|
16
|
|
|
|
|
532163
|
|
|
16
|
|
|
|
|
80
|
|
4
|
16
|
|
|
16
|
|
1068
|
use Method::Signatures; |
|
16
|
|
|
|
|
36501
|
|
|
16
|
|
|
|
|
132
|
|
5
|
16
|
|
|
16
|
|
5091
|
use Moo::Role; |
|
16
|
|
|
|
|
16
|
|
|
16
|
|
|
|
|
144
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Logging for EventStreamr |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.3'; # VERSION: Generated by DZP::OurPkg:Version |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @methods = qw( |
13
|
|
|
|
|
|
|
log trace debug info warn error fatal |
14
|
|
|
|
|
|
|
is_trace is_debug is_info is_warn is_error is_fatal |
15
|
|
|
|
|
|
|
logexit logwarn error_warn logdie error_die |
16
|
|
|
|
|
|
|
logcarp logcluck logcroak logconfess |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has _logger => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
isa => sub { 'Log::Log4perl::Logger' }, |
22
|
|
|
|
|
|
|
lazy => 1, |
23
|
|
|
|
|
|
|
builder => 1, |
24
|
|
|
|
|
|
|
handles => \@methods, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has _log_path => ( is => 'ro', lazy => 1, builder => 1 ); |
28
|
|
|
|
|
|
|
has _log_level => ( is => 'ro', lazy => 1, builder => 1 ); |
29
|
|
|
|
|
|
|
has log_config => ( is => 'ro', lazy => 1, builder => 1 ); |
30
|
|
|
|
|
|
|
|
31
|
16
|
50
|
|
16
|
|
14842
|
method _build_log_config() { |
|
2
|
|
|
2
|
|
684
|
|
|
2
|
|
|
|
|
18
|
|
32
|
2
|
|
50
|
|
|
20
|
my $log_level = $self->_log_level || "INFO, LOG1"; |
33
|
2
|
|
50
|
|
|
15
|
my $log_path = $self->_log_path || "/tmp"; |
34
|
2
|
|
|
|
|
15
|
return qq( |
35
|
|
|
|
|
|
|
log4perl.rootLogger = $log_level |
36
|
|
|
|
|
|
|
log4perl.appender.SCREEN = Log::Log4perl::Appender::Screen |
37
|
|
|
|
|
|
|
log4perl.appender.SCREEN.stderr = 0 |
38
|
|
|
|
|
|
|
log4perl.appender.SCREEN.layout = Log::Log4perl::Layout::PatternLayout |
39
|
|
|
|
|
|
|
log4perl.appender.SCREEN.layout.ConversionPattern = %m %n |
40
|
|
|
|
|
|
|
log4perl.appender.LOG1 = Log::Log4perl::Appender::File |
41
|
|
|
|
|
|
|
log4perl.appender.LOG1.utf8 = 1 |
42
|
|
|
|
|
|
|
log4perl.appender.LOG1.filename = $log_path/eventstreamr.log |
43
|
|
|
|
|
|
|
log4perl.appender.LOG1.mode = append |
44
|
|
|
|
|
|
|
log4perl.appender.LOG1.layout = Log::Log4perl::Layout::PatternLayout |
45
|
|
|
|
|
|
|
log4perl.appender.LOG1.layout.ConversionPattern = %d %p %m %n |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
16
|
50
|
|
16
|
|
7442
|
method _build__log_level() { |
|
2
|
|
|
2
|
|
726
|
|
|
2
|
|
|
|
|
16
|
|
50
|
2
|
50
|
|
|
|
22
|
if ( defined $self->{config}){ |
|
|
50
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
return $self->{config}{log_level}; |
52
|
|
|
|
|
|
|
} elsif (defined $self->{log_level}) { |
53
|
2
|
|
|
|
|
16
|
return $self->{log_level}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
16
|
50
|
|
16
|
|
7019
|
method _build__log_path() { |
|
2
|
|
|
2
|
|
636
|
|
|
2
|
|
|
|
|
12
|
|
58
|
2
|
50
|
|
|
|
20
|
if (defined $self->{config}) { |
|
|
50
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
return $self->{config}{config_path}; |
60
|
|
|
|
|
|
|
} elsif (defined $self->{config_path}) { |
61
|
2
|
|
|
|
|
15
|
return $self->{config_path}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
around $_ => sub { |
66
|
|
|
|
|
|
|
my $orig = shift; |
67
|
|
|
|
|
|
|
my $this = shift; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# one level for this method itself |
70
|
|
|
|
|
|
|
# two levels for Class:;MOP::Method::Wrapped (the "around" wrapper) |
71
|
|
|
|
|
|
|
# one level for Moose::Meta::Method::Delegation (the "handles" wrapper) |
72
|
|
|
|
|
|
|
local $Log::Log4perl::caller_depth; |
73
|
|
|
|
|
|
|
$Log::Log4perl::caller_depth += 4; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $return = $this->$orig(@_); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$Log::Log4perl::caller_depth -= 4; |
78
|
|
|
|
|
|
|
return $return; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} foreach @methods; |
81
|
|
|
|
|
|
|
|
82
|
16
|
50
|
|
16
|
|
7983
|
method _build__logger() { |
|
2
|
|
|
2
|
|
1159
|
|
|
2
|
|
|
|
|
16
|
|
83
|
2
|
|
|
|
|
6
|
my $this = shift; |
84
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
5
|
my $loggerName = ref($this); |
86
|
2
|
|
|
|
|
15
|
$self->log_config; |
87
|
2
|
|
|
|
|
9
|
Log::Log4perl->init_once(\$self->log_config); |
88
|
2
|
|
|
|
|
8265
|
return Log::Log4perl->get_logger($loggerName) |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=pod |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=encoding UTF-8 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 NAME |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
App::EventStreamr::Roles::Logger - Logging for EventStreamr |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 VERSION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
version 0.3 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SYNOPSIS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Provides a central logging service for EventStreamr |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 DESCRIPTION |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
with('App::EventStreamr::Roles::Logger'); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Can be consumed by any EventStreamr package. Config must exist for |
116
|
|
|
|
|
|
|
it to end up in the central log. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Inspiratation/Credit here -> http://stackoverflow.com/questions/3018528/making-self-logging-modules-with-loglog4perl |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 AUTHOR |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Leon Wright < techman@cpan.org > |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Leon Wright. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This is free software, licensed under: |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
The GNU Affero General Public License, Version 3, November 2007 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |