File Coverage

blib/lib/Elasticsearch/Logger/LogAny.pm
Criterion Covered Total %
statement 23 23 100.0
branch 4 4 100.0
condition n/a
subroutine 7 7 100.0
pod n/a
total 34 34 100.0


line stmt bran cond sub pod time code
1             package Elasticsearch::Logger::LogAny;
2             $Elasticsearch::Logger::LogAny::VERSION = '1.05';
3 42     42   31919 use Moo;
  42         130  
  42         298  
4             with 'Elasticsearch::Role::Logger';
5 42     42   16276 use Elasticsearch::Util qw(parse_params to_list);
  42         91  
  42         409  
6 42     42   19219 use namespace::clean;
  42         94  
  42         383  
7              
8 42     42   51659 use Log::Any();
  42         98972  
  42         1165  
9 42     42   39986 use Log::Any::Adapter();
  42         261966  
  42         9272  
10              
11             #===================================
12             sub _build_log_handle {
13             #===================================
14 71     71   46029 my $self = shift;
15 71 100       632 if ( my @args = to_list( $self->log_to ) ) {
16 3         31 Log::Any::Adapter->set( { category => $self->log_as }, @args );
17             }
18 71         14745 Log::Any->get_logger( category => $self->log_as );
19             }
20              
21             #===================================
22             sub _build_trace_handle {
23             #===================================
24 43     43   76527 my $self = shift;
25 43 100       550 if ( my @args = to_list( $self->trace_to ) ) {
26 3         35 Log::Any::Adapter->set( { category => $self->trace_as }, @args );
27             }
28 43         3574 Log::Any->get_logger( category => $self->trace_as );
29             }
30              
31             1;
32              
33             # ABSTRACT: A Log::Any-based Logger implementation
34              
35             __END__
36              
37             =pod
38              
39             =encoding UTF-8
40              
41             =head1 NAME
42              
43             Elasticsearch::Logger::LogAny - A Log::Any-based Logger implementation
44              
45             =head1 VERSION
46              
47             version 1.05
48              
49             =head1 DESCRIPTION
50              
51             L<Elasticsearch::Logger::LogAny> provides event logging and the tracing
52             of request/response conversations with Elasticsearch nodes via the
53             L<Log::Any> module.
54              
55             I<Logging> refers to log events, such as node failures, pings, sniffs, etc,
56             and should be enabled for monitoring purposes.
57              
58             I<Tracing> refers to the actual HTTP requests and responses sent
59             to Elasticsearch nodes. Tracing can be enabled for debugging purposes,
60             or for generating a pretty-printed C<curl> script which can be used for
61             reporting problems.
62              
63             =head1 CONFIGURATION
64              
65             Logging and tracing can be enabled using L<Log::Any::Adapter>, or by
66             passing options to L<Elasticsearch/new()>.
67              
68             =head2 USING LOG::ANY::ADAPTER
69              
70             Send all logging and tracing to C<STDERR>:
71              
72             use Log::Any::Adapter qw(Stderr);
73             use Elasticsearch;
74             my $e = Elasticsearch->new;
75              
76             Send logging to a file, and tracing to Stderr:
77              
78             use Log::Any::Adapter();
79             Log::Any::Adapter->set(
80             { category => 'elasticsearch.event' },
81             'File',
82             '/path/to/file.log'
83             );
84             Log::Any::Adapter->set(
85             { category => 'elasticsearch.trace' },
86             'Stderr'
87             );
88              
89             use Elasticsearch;
90             my $e = Elasticsearch->new;
91              
92             =head2 USING C<log_to> AND C<trace_to>
93              
94             Send all logging and tracing to C<STDERR>:
95              
96             use Elasticsearch;
97             my $e = Elasticsearch->new(
98             log_to => 'Stderr',
99             trace_to => 'Stderr'
100             );
101              
102             Send logging to a file, and tracing to Stderr:
103              
104             use Elasticsearch;
105             my $e = Elasticsearch->new(
106             log_to => ['File', '/path/to/file.log'],
107             trace_to => 'Stderr'
108             );
109              
110             See L<Log::Any::Adapter> for more.
111              
112             =head1 AUTHOR
113              
114             Clinton Gormley <drtech@cpan.org>
115              
116             =head1 COPYRIGHT AND LICENSE
117              
118             This software is Copyright (c) 2014 by Elasticsearch BV.
119              
120             This is free software, licensed under:
121              
122             The Apache License, Version 2.0, January 2004
123              
124             =cut