Mojo/WebSocketProxy/RequestLogger.pm

filter: Statementstmt 80.4% 99 / 123 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.2% 17 / 22 Podpod 100% 16 / 16 totaltotal 82.2% 134 / 163 CC 2 SCAR 2.7
CC
2
Cov
81%
__ANON__
2.0
set_handler
2.0
critf
2.0
CRAP 1.3
« Mojo/WebSocketProxy/Backend.pm ↑ Summary Mojo/WebSocketProxy.pm »
1 package Mojo::WebSocketProxy::RequestLogger;
2  
3 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 class Mojo::WebSocketProxy::RequestLogger;
8  
9 22 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 ▶use UUID::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 22 our $VERSION = '0.16'; ## VERSION
13  
14 =head1 NAME
15  
16 Log::Any::Adapter::DERIV - standardised logging to STDERR and JSON file
17  
18 =head1 SYNOPSIS
19  
20 use Mojo::WebSocketProxy::RequestLogger;
21  
22 my $logger = Mojo::WebSocketProxy::RequestLogger->new();
23  
24 $logger->info('This is an info message');
25  
26 =head1 DESCRIPTION
27  
28 Mojo::WebSocketProxy::RequestLogger is a request logger for Mojo::WebSocketProxy.
29  
30 =head1 METHODS
31  
32 =head2 DOES
33  
34 =over 4
35  
36 =item B<DOES($role)>
37  
38 Check if an object or class does a particular role.
39  
40 =back
41  
42 =head2 META
43  
44 =over 4
45  
46 =item B<META()>
47  
48 Return the meta object for the class.
49  
50 =back
51  
52 =head2 new
53  
54 =over 4
55  
56 =item B<new()>
57  
58 Create a new `Mojo::WebSocketProxy::RequestLogger` object.
59  
60 =back
61  
62 =cut
63  
64 22 field $context;
65  
66 10 ▶our $log_handler = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
67 10 my ($level, $message, $context, @params) = @_;
68  
69 10 ▶ if (scalar @params) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @params) 5 5 10
70 5 return $log->$level($message, @params);
71 }
72  
73 5 return $log->$level($message, $context);
74 22 };
75  
76 =head2 set_handler
77  
78 set the handler for message logging
79  
80 =cut
81  
82 0 ▶sub set_handler {
Subroutine set_handler: not called CC=1 SCAR=6.9
Pod documented
83 0 my ($self, $custom_handler) = @_;
84 0 $log_handler = $custom_handler;
85 }
86  
87 BUILD {
88 $context->{correlation_id} = UUID::Tiny::create_UUID_as_string(UUID::Tiny::UUID_V4);
89 }
90  
91 22 =head2 infof
92  
93 info format message logging
94  
95 =cut
96  
97 1 ▶method infof($message, @params) {
Subroutine infof: called CC=1 SCAR=0.0
Pod documented
98 1 $log_handler->('infof', $message, $context, @params);
99 22 }
100  
101 =head2 tracef
102  
103 trace format message logging
104  
105 =cut
106  
107 1 ▶method tracef($message, @params) {
Subroutine tracef: called CC=1 SCAR=0.0
Pod documented
108 1 $log_handler->('tracef', $message, $context, @params);
109 22 }
110  
111 =head2 errorf
112  
113 error format message logging
114  
115 =cut
116  
117 1 ▶method errorf($message, @params) {
Subroutine errorf: called CC=1 SCAR=0.0
Pod documented
118 1 $log_handler->('errorf', $message, $context, @params);
119 22 }
120  
121 =head2 warnf
122  
123 warn format message logging
124  
125 =cut
126  
127 1 ▶method warnf($message, @params) {
Subroutine warnf: called CC=1 SCAR=0.0
Pod documented
128 1 $log_handler->('warningf', $message, $context, @params);
129 22 }
130  
131 =head2 debugf
132  
133 debug format message logging
134  
135 =cut
136  
137 1 ▶method debugf($message, @params) {
Subroutine debugf: called CC=1 SCAR=0.0
Pod documented
138 1 $log_handler->('debugf', $message, $context, @params);
139 22 }
140  
141 =head2 critf
142  
143 critical format message logging
144  
145 =cut
146  
147 0 ▶method critf($message, @params) {
Subroutine critf: not called CC=1 SCAR=6.9
Pod documented
148 0 $log_handler->('critf', $message, $context, @params);
149 22 }
150  
151 =head2 info
152  
153 info message logging
154  
155 =cut
156  
157 1 ▶method info($message) {
Subroutine info: called CC=1 SCAR=0.0
Pod documented
158 1 $log_handler->('info', $message, $context);
159 22 }
160  
161 =head2 trace
162  
163 trace message logging
164  
165 =cut
166  
167 1 ▶method trace($message) {
Subroutine trace: called CC=1 SCAR=0.0
Pod documented
168 1 $log_handler->('trace', $message, $context);
169 22 }
170  
171 =head2 error
172  
173 error message logging
174  
175 =cut
176  
177 1 ▶method error($message) {
Subroutine error: called CC=1 SCAR=0.0
Pod documented
178 1 $log_handler->('error', $message, $context);
179 22 }
180  
181 =head2 warn
182  
183 warn message logging
184  
185 =cut
186  
187 1 ▶method warn($message) {
Subroutine warn: called CC=1 SCAR=0.0
Pod documented
188 1 $log_handler->('warning', $message, $context);
189 22 }
190  
191 =head2 debug
192  
193 debug message logging
194  
195 =cut
196  
197 1 ▶method debug($message) {
Subroutine debug: called CC=1 SCAR=0.0
Pod documented
198 1 $log_handler->('debug', $message, $context);
199 22 }
200  
201 =head2 crit
202  
203 crit message logging
204  
205 =cut
206  
207 0 ▶method crit($message) {
Subroutine crit: not called CC=1 SCAR=6.9
Pod documented
208 0 $log_handler->('crit', $message, $context);
209 22 }
210  
211 =head2 get_context
212  
213 get the value of context
214  
215 =cut
216  
217 1 ▶method get_context() {
Subroutine get_context: called CC=1 SCAR=0.0
Pod documented
218 1 return $context;
219 22 }
220  
221 =head2 add_context_key
222  
223 add a key in log context hash
224  
225 =cut
226  
227 0 ▶method add_context_key($key, $value) {
Subroutine add_context_key: not called CC=1 SCAR=6.9
Pod documented
228 0 $context->{$key} = $value;
229 22 }
230  
231 =head2 remove_context_key
232  
233 remove key from context
234  
235 =cut
236  
237 0 ▶method remove_context_key($key) {
Subroutine remove_context_key: not called CC=1 SCAR=6.9
Pod documented
238 0 delete $context->{$key};
239 22 }
240  
241 22 1;
242  
243 =head1 AUTHOR
244  
245 Deriv Group Services Ltd. C<< DERIV@cpan.org >>
246  
247 =head1 COPYRIGHT AND LICENSE
248  
249 Copyright Deriv Group Services Ltd 2020-2021. Licensed under the same terms as Perl itself.
« Mojo/WebSocketProxy/Backend.pm ↑ Summary Mojo/WebSocketProxy.pm »