line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Dispatch::MongoDB; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
9156
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
65
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp qw[ confess ]; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
67
|
|
7
|
1
|
|
|
1
|
|
6
|
use Scalar::Util qw[ blessed ]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
97
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1791
|
use Log::Dispatch::Output; |
|
1
|
|
|
|
|
97942
|
|
|
1
|
|
|
|
|
42
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
14
|
use base qw[ Log::Dispatch::Output ]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
289
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
15
|
0
|
|
0
|
|
|
|
my $class = ref $proto || $proto; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my %p = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$self->_basic_init(%p); |
22
|
0
|
|
|
|
|
|
$self->_local_init(%p); |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _local_init { |
28
|
0
|
|
|
0
|
|
|
my ($self, %params) = @_; |
29
|
0
|
0
|
0
|
|
|
|
(exists $params{collection} && blessed $params{collection} && $params{collection}->isa('MongoDB::Collection')) |
|
|
|
0
|
|
|
|
|
30
|
|
|
|
|
|
|
|| confess "You must supply a MongoDB::Collection object in the collection slot"; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$self->{_collection} = $params{collection}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub log_message { |
36
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
37
|
0
|
|
|
|
|
|
my %p = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$self->{_collection}->insert( \%p ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# ABSTRACT: A MongoDB backend for Log::Dispatch |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
48
|
|
|
|
|
|
|
=pod |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 NAME |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Log::Dispatch::MongoDB - A MongoDB backend for Log::Dispatch |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 VERSION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
version 0.001 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SYNOPSIS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $log = Log::Dispatch->new; |
61
|
|
|
|
|
|
|
$log->add( |
62
|
|
|
|
|
|
|
Log::Dispatch::MongoDB->new( |
63
|
|
|
|
|
|
|
name => 'my_web_logger', |
64
|
|
|
|
|
|
|
min_level => 'debug', |
65
|
|
|
|
|
|
|
collection => $mongo_db->get_collection('web_log') |
66
|
|
|
|
|
|
|
) |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$log->debug("Testing feature $x"); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$log->log( |
72
|
|
|
|
|
|
|
level => 'info', |
73
|
|
|
|
|
|
|
message => 'Started processing web page', |
74
|
|
|
|
|
|
|
info => { |
75
|
|
|
|
|
|
|
referer => $ENV{HTTP_REFERER}, |
76
|
|
|
|
|
|
|
user_agent => $ENV{HTTP_USER_AGENT}, |
77
|
|
|
|
|
|
|
remote_addr => $ENV{REMOTE_ADDR}, |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 DESCRIPTION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This is a L<MongoDB> backend for L<Log::Dispatch>. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
L<MongoDB> is especially adept for logging because of it's asynchronous |
86
|
|
|
|
|
|
|
insert behavior, which means that your logging won't slow down your |
87
|
|
|
|
|
|
|
application. It is also nice in that you can store structured data |
88
|
|
|
|
|
|
|
as well as simple messages. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 METHODS |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 log |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
With the C<log> method, we not only store the level and message, but we |
95
|
|
|
|
|
|
|
store any other information you choose to passed in. Note that this feature |
96
|
|
|
|
|
|
|
does not work if you use the C<info>, C<warn>, C<debug> methods, etc. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SEE ALSO |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L<http://blog.mongodb.org/post/172254834/mongodb-is-fantastic-for-logging> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Stevan Little <stevan.little@iinteractive.com> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Infinity Interactive, Inc.. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
111
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|