Codebase list liblog-report-perl / a28770b
Update upstream source from tag 'upstream/1.32' Update to upstream version '1.32' with Debian dir 55b4dd3da6ae3ba45d4eff1f2d6958ecfcbca03e gregor herrmann 3 years ago
48 changed file(s) with 297 addition(s) and 184 deletion(s). Raw diff Collapse all Expand all
55
66 TODO:
77 . connect to Message::Passing framework
8
9 version 1.32: Tue 26 Jan 09:13:31 CET 2021
10
11 Fixes:
12 - ::Dancer2, use correct VERSION, github issue#3
13 - ::Dancer2, fix stacktrace sent to browser with show_errors disabled
14 by [Andy Beverley], github issue#7
15
16 version 1.31: Fri 15 Jan 16:35:39 CET 2021
17
18 Fixes:
19 - another attempt on issue #6, exceptions with specific destination
20 are not caught by ::Try
21 - previous release broke ::Try::hide() [Andy Beverley]
22
23 version 1.30: Fri 15 Jan 12:46:14 CET 2021
24
25 Fixes:
26 - recursive errors when file cannot be written for ::File dispatcher
27 github issue#4 [Tom Hukins]
28 - exceptions with specific destination are not caught by ::Try
29 github issue#6 [Andy Beverley]
30 - redirected exception messages forget their explicit dispatcher
31 destination. Github issue#6
32
33 Improvements:
34 - use ::Util::expand_reasons() for ::Try::hide()
35 - require Log::Report::Options 1.07 for more expand_reasons options
836
937 version 1.29: Fri 8 Nov 09:18:01 CET 2019
1038
3333 "requires" : {
3434 "Devel::GlobalDestruction" : "0.09",
3535 "Encode" : "2.00",
36 "Log::Report::Optional" : "1.03",
36 "Log::Report::Optional" : "1.07",
3737 "Scalar::Util" : "0",
3838 "String::Print" : "0.91",
3939 "Sys::Syslog" : "0.27",
5353 "web" : "https://github.com/markov2/perl5-Log-Report"
5454 }
5555 },
56 "version" : "1.29",
56 "version" : "1.32",
5757 "x_serialization_backend" : "JSON::PP version 2.94"
5858 }
1919 requires:
2020 Devel::GlobalDestruction: '0.09'
2121 Encode: '2.00'
22 Log::Report::Optional: '1.03'
22 Log::Report::Optional: '1.07'
2323 Scalar::Util: '0'
2424 String::Print: '0.91'
2525 Sys::Syslog: '0.27'
2828 homepage: http://perl.overmeer.net/CPAN/
2929 license: http://dev.perl.org/licenses/
3030 repository: https://github.com/markov2/perl5-Log-Report.git
31 version: '1.29'
31 version: '1.32'
3232 x_serialization_backend: 'CPAN::Meta::YAML version 0.011'
11
22 use 5.010;
33
4 my $version = '1.29';
4 my $version = '1.32';
55
66 my %prereq =
77 ( Test::More => '0.86'
99 , Encode => '2.00'
1010 , Scalar::Util => 0
1111 , Devel::GlobalDestruction => '0.09'
12 , Log::Report::Optional => '1.03'
12 , Log::Report::Optional => '1.07'
1313 , String::Print => '0.91'
1414 );
1515
0 === README for Log-Report version 1.28
1 = Generated on Tue May 14 09:25:07 2019 by OODoc 2.02
0 === README for Log-Report version 1.30
1 = Generated on Fri Jan 15 12:45:38 2021 by OODoc 2.02
22
33 There are various ways to install this module:
44
88 (2) if you use Windows, have a look at http://ppm.activestate.com/
99
1010 (3) if you have downloaded this module manually (as root/administrator)
11 gzip -d Log-Report-1.28.tar.gz
12 tar -xf Log-Report-1.28.tar
13 cd Log-Report-1.28
11 gzip -d Log-Report-1.30.tar.gz
12 tar -xf Log-Report-1.30.tar
13 cd Log-Report-1.30
1414 perl Makefile.PL
1515 make # optional
1616 make test # optional
1717 make install
1818
1919 For usage, see the included manual-pages or
20 http://search.cpan.org/dist/Log-Report-1.28/
20 http://search.cpan.org/dist/Log-Report-1.30/
2121
2222 Please report problems to
2323 http://rt.cpan.org/Dist/Display.html?Queue=Log-Report
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Dancer::Logger::LogReport;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'Dancer::Logger::Abstract', 'Exporter';
1313
6060
6161 =head1 SEE ALSO
6262
63 This module is part of Log-Report distribution version 1.29,
64 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
63 This module is part of Log-Report distribution version 1.32,
64 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
6565
6666 =head1 LICENSE
6767
68 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
68 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
6969
7070 This program is free software; you can redistribute it and/or modify it
7171 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Dancer2::Logger::LogReport;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 # ABSTRACT: Dancer2 logger engine for Log::Report
1313
7070
7171 =head1 SEE ALSO
7272
73 This module is part of Log-Report distribution version 1.29,
74 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
73 This module is part of Log-Report distribution version 1.32,
74 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
7575
7676 =head1 LICENSE
7777
78 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
78 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
7979
8080 This program is free software; you can redistribute it and/or modify it
8181 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Dancer2::Plugin::LogReport::Message;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use parent 'Log::Report::Message';
1313
7676
7777 =head1 SEE ALSO
7878
79 This module is part of Log-Report distribution version 1.29,
80 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
79 This module is part of Log-Report distribution version 1.32,
80 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
8181
8282 =head1 LICENSE
8383
84 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
84 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
8585
8686 This program is free software; you can redistribute it and/or modify it
8787 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Dancer2::Plugin::LogReport;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212
1313 use warnings;
3131 { my $class = shift;
3232
3333 # Import Log::Report into the caller. Import options get passed through
34 my $level = $Dancer2::VERSION > 0.166001 ? '+1' : '+2';
34 my $level = $Dancer2::Plugin::VERSION > 0.166001 ? '+1' : '+2';
3535 Log::Report->import($level, @_, syntax => 'LONG');
3636
3737 # Ensure the overridden import method is called (from Exporter::Tiny)
6262 name => 'core.app.route_exception',
6363 code => sub {
6464 my ($app, $error) = @_;
65 report 'PANIC' => $error;
65 # If there is no request object then we are in an early hook
66 # and Dancer will not handle an exception cleanly (which will
67 # result in a stacktrace to the browser, a potential security
68 # vulnerability). Therefore in this case do not raise as fatal.
69 my $is_fatal = $app->request ? 1 : 0;
70 report {is_fatal => $is_fatal}, 'PANIC' => $error;
6671 },
6772 ),
6873 );
104109 my $sm = $settings->{session_messages} // \@default_reasons;
105110 $session_messages{$_} = 1
106111 for ref $sm eq 'ARRAY' ? @$sm : $sm;
107
108 # In a production server, we don't want the end user seeing (unexpected)
109 # exception messages, for both security and usability. If we detect
110 # that this is a production server (show_errors is 0), then we change
111 # the specific error to a generic error, when displayed to the user.
112 # The message can be customised in the config file.
113 my $fatal_error_message = $settings->{fatal_error_message}
114 // "An unexpected error has occurred";
115
116 unless($dsl->app->config->{show_errors})
117 { $hide_real_message->{$_} = $fatal_error_message
118 for qw/FAULT ALERT FAILURE PANIC/;
119 }
120112
121113 if(my $forward_template = $settings->{forward_template})
122114 { # Add a route for the specified template
213205 # for request(), which is used to access the cookies of a session.
214206 return unless $app->request;
215207
208 # In a production server, we don't want the end user seeing (unexpected)
209 # exception messages, for both security and usability. If we detect
210 # that this is a production server (show_errors is 0), then we change
211 # the specific error to a generic error, when displayed to the user.
212 # The message can be customised in the config file.
213 # We evaluate this each message to allow show_errors to be set in the
214 # application (specifically makes testing a lot easier)
215 my $fatal_error_message = !$dsl->app->config->{show_errors}
216 && ($_settings->{fatal_error_message} // "An unexpected error has occurred");
217 $hide_real_message->{$_} = $fatal_error_message
218 for qw/FAULT ALERT FAILURE PANIC/;
219
216220 my $r = $msg->reason;
217221 if(my $newm = $hide_real_message->{$r})
218222 { $msg = __$newm;
224228 push @$msgs, $msg;
225229 $session->write($messages_variable => $msgs);
226230
227 return $dsl;
231 return ($dsl || undef, $msg);
228232 }
229233
230234 #------
231235
232236 sub _forward_home($)
233 { my $dsl = _message_add(shift) || _get_dsl();
237 { my ($dsl, $msg) = _message_add(shift);
238 $dsl ||= _get_dsl();
239
234240 my $page = $_settings->{forward_url} || '/';
235241
236 # Don't forward if it's a GET request to the error page, as it will
237 # cause a recursive loop. In this case, do nothing, and let dancer
238 # handle it.
242 # Don't forward if it's a GET request to the error page, as it will cause a
243 # recursive loop. In this case, return the fatal error message as plain
244 # text to render that instead. If we can't do that because it's too early
245 # in the request, then let Dancer handle this with its default error
246 # handling
239247 my $req = $dsl->app->request or return;
240 return if $req->uri eq $page && $req->is_get;
248
249 $dsl->send_as(plain => "$msg")
250 if $req->uri eq $page && $req->is_get;
241251
242252 $dsl->redirect($page);
243253 }
512512
513513 =head1 SEE ALSO
514514
515 This module is part of Log-Report distribution version 1.29,
516 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
515 This module is part of Log-Report distribution version 1.32,
516 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
517517
518518 =head1 LICENSE
519519
520 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
520 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
521521
522522 This program is free software; you can redistribute it and/or modify it
523523 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::DBIC::Profiler;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'DBIx::Class::Storage::Statistics';
1313
3232
3333 =head1 SEE ALSO
3434
35 This module is part of Log-Report distribution version 1.29,
36 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
35 This module is part of Log-Report distribution version 1.32,
36 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
3737
3838 =head1 LICENSE
3939
40 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
40 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
4141
4242 This program is free software; you can redistribute it and/or modify it
4343 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Die;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'Exporter';
1313
7777
7878 =head1 SEE ALSO
7979
80 This module is part of Log-Report distribution version 1.29,
81 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
80 This module is part of Log-Report distribution version 1.32,
81 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
8282
8383 =head1 LICENSE
8484
85 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
85 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
8686
8787 This program is free software; you can redistribute it and/or modify it
8888 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Dispatcher::Callback;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'Log::Report::Dispatcher';
1313
173173
174174 =head1 SEE ALSO
175175
176 This module is part of Log-Report distribution version 1.29,
177 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
176 This module is part of Log-Report distribution version 1.32,
177 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
178178
179179 =head1 LICENSE
180180
181 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
181 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
182182
183183 This program is free software; you can redistribute it and/or modify it
184184 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Dispatcher::File;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'Log::Report::Dispatcher';
1313
6666 : $self->{LRDF_filename} ? $self->{LRDF_output}
6767 : ();
6868
69 $_->close for @close;
69 $_ && $_->close for @close;
7070 $self;
7171 }
7272
8989 $self->{LRDF_filename} = $to;
9090 my $binmode = $self->{replace} ? '>' : '>>';
9191
92 my $f = $self->{LRDF_output} = IO::File->new($to, $binmode)
93 or fault __x"cannot write log into {file} with mode {binmode}"
92 my $f = $self->{LRDF_output} = IO::File->new($to, $binmode);
93 unless($f)
94 { # avoid logging error to myself (issue #4)
95 my $msg = __x"cannot write log into {file} with mode '{binmode}'"
9496 , binmode => $binmode, file => $to;
97 if(my @disp = grep $_->name ne $name, Log::Report::dispatcher('list'))
98 { $msg->to($disp[0]->name);
99 error $msg;
100 }
101 else
102 { die $msg;
103 }
104 }
105
95106 $f->autoflush;
96107 return $self->{LRDF_output} = $f;
97108 }
258258
259259 =head1 SEE ALSO
260260
261 This module is part of Log-Report distribution version 1.29,
262 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
261 This module is part of Log-Report distribution version 1.32,
262 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
263263
264264 =head1 LICENSE
265265
266 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
266 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
267267
268268 This program is free software; you can redistribute it and/or modify it
269269 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Dispatcher::Log4perl;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'Log::Report::Dispatcher';
1313
229229
230230 =head1 SEE ALSO
231231
232 This module is part of Log-Report distribution version 1.29,
233 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
232 This module is part of Log-Report distribution version 1.32,
233 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
234234
235235 =head1 LICENSE
236236
237 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
237 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
238238
239239 This program is free software; you can redistribute it and/or modify it
240240 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Dispatcher::LogDispatch;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'Log::Report::Dispatcher';
1313
193193
194194 =head1 SEE ALSO
195195
196 This module is part of Log-Report distribution version 1.29,
197 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
196 This module is part of Log-Report distribution version 1.32,
197 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
198198
199199 =head1 LICENSE
200200
201 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
201 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
202202
203203 This program is free software; you can redistribute it and/or modify it
204204 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Dispatcher::Perl;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'Log::Report::Dispatcher';
1313
3838
3939 =head1 SEE ALSO
4040
41 This module is part of Log-Report distribution version 1.29,
42 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
41 This module is part of Log-Report distribution version 1.32,
42 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
4343
4444 =head1 LICENSE
4545
46 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
46 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
4747
4848 This program is free software; you can redistribute it and/or modify it
4949 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Dispatcher::Syslog;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'Log::Report::Dispatcher';
1313
222222
223223 =head1 SEE ALSO
224224
225 This module is part of Log-Report distribution version 1.29,
226 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
225 This module is part of Log-Report distribution version 1.32,
226 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
227227
228228 =head1 LICENSE
229229
230 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
230 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
231231
232232 This program is free software; you can redistribute it and/or modify it
233233 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Dispatcher::Try;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'Log::Report::Dispatcher';
1313
1616
1717 use Log::Report 'log-report', syntax => 'SHORT';
1818 use Log::Report::Exception ();
19 use Log::Report::Util qw/%reason_code/;
19 use Log::Report::Util qw/%reason_code expand_reasons/;
2020 use List::Util qw/first/;
2121
2222
4848 sub exceptions() { @{shift->{exceptions}} }
4949
5050
51 sub hides($)
52 { my $h = shift->{hides} or return 0;
53 keys %$h ? $h->{(shift)} : 1;
54 }
51 sub hides($) { $_[0]->{LRDT_hides}{$_[1]} }
5552
5653
5754 sub hide(@)
5855 { my $self = shift;
59 my @h = map { ref $_ eq 'ARRAY' ? @$_ : defined($_) ? $_ : () } @_;
60
61 $self->{hides}
62 = @h==0 ? undef
63 : @h==1 && $h[0] eq 'ALL' ? {} # empty HASH = ALL
64 : @h==1 && $h[0] eq 'NONE' ? undef
65 : +{ map +($_ => 1), @h };
56 my @reasons = expand_reasons(@_ > 1 ? \@_ : shift);
57 $self->{LRDT_hides} = +{ map +($_ => 1), @reasons };
6658 }
6759
6860
10799 sub success() { ! defined shift->{died}}
108100
109101
110
111102 sub wasFatal(@)
112103 { my ($self, %args) = @_;
113104 defined $self->{died} or return ();
4444
4545 =head1 DESCRIPTION
4646
47 The L<Log::Report::try()|Log::Report/"Report Production and Configuration"> catches errors in the block (CODE
48 reference) which is just following the function name. All
49 dispatchers are temporarily disabled by C<try>, and messages
50 which are reported are collected within a temporary dispatcher
51 named C<try>. When the CODE has run, that C<try> dispatcher
52 is returned in C<$@>, and all original dispatchers reinstated.
53
54 Then, after the C<try> has finished, the routine which used
55 the "try" should decide what to do with the collected reports.
56 These reports are collected as L<Log::Report::Exception|Log::Report::Exception> objects.
57 They can be ignored, or thrown to a higher level try... causing
58 an exit of the program if there is none.
47 The B<try> works like Perl's build-in C<eval()>, but implements
48 real exception handling which Perl core lacks.
49
50 The L<Log::Report::try()|Log::Report/"Report Production and Configuration"> function creates this C<::Try> dispatcher
51 object with name 'try'. After the C<try()> is over, you can find
52 the object in C<$@>. The C<$@> as C<::Try> object behaves exactly
53 as the C<$@> produced by C<eval>, but has many added features.
54
55 The C<try()> function catches fatal errors happening inside the BLOCK
56 (CODE reference which is just following the function name) into the
57 C<::Try> object C<$@>. The errors are not automatically progressed to
58 active dispatchers. However, non-fatal exceptions (like info or notice)
59 are also collected (unless not accepted, see L<new(accept)|Log::Report::Dispatcher/"Constructors">, but also
60 immediately passed to the active dispatchers (unless the reason is hidden,
61 see L<new(hide)|Log::Report::Dispatcher::Try/"Constructors">)
62
63 After the C<try()> has run, you can introspect the collected exceptions.
64 Typically, you use L<wasFatal()|Log::Report::Dispatcher::Try/"Status"> to get the exception which terminated
65 the run of the BLOCK.
5966
6067 Extends L<"DESCRIPTION" in Log::Report::Dispatcher|Log::Report::Dispatcher/"DESCRIPTION">.
6168
102109
103110 =item format_reason => 'UPPERCASE'|'LOWERCASE'|'UCFIRST'|'IGNORE'|CODE
104111
105 =item hide => REASON|ARRAY|'ALL'|'NONE'
112 =item hide => REASONS|ARRAY|'ALL'|'NONE'
106113
107114 [1.09] see L<hide()|Log::Report::Dispatcher::Try/"Accessors">
108115
141148 Returns all collected C<Log::Report::Exceptions>. The last of
142149 them may be a fatal one. The other are non-fatal.
143150
144 =item $obj-E<gt>B<hide>(REASON|REASONS|ARRAY|'ALL'|'NONE')
151 =item $obj-E<gt>B<hide>(@reasons)
145152
146153 [1.09] By default, the try will only catch messages which stop the
147154 execution of the block (errors etc, internally a 'die'). Other messages
148 are passed to parent try blocks, if none than to the dispatchers.
149
150 This option gives the opportunity to block, for instance, trace messages.
151 Those messages are still collected inside the try object, so may get
152 passed-on later via L<reportAll()|Log::Report::Dispatcher::Try/"Logging"> if you like.
155 are passed to the parent dispatchers.
156
157 This option gives the opportunity to stop, for instance, trace messages.
158 Those messages are still collected inside the try object (unless excluded
159 by L<new(accept)|Log::Report::Dispatcher/"Constructors">), so may get passed-on later via L<reportAll()|Log::Report::Dispatcher::Try/"Logging"> if
160 you like.
153161
154162 Be warned: Using this method will reset the whole 'hide' configuration:
155163 it's a I<set> not an I<add>.
157165 example: change the setting of the running block
158166
159167 my $parent_try = dispatcher 'active-try';
160 parent_try->hide('NONE');
161
162 =item $obj-E<gt>B<hides>(REASON)
168 $parent_try->hide('ALL');
169
170 =item $obj-E<gt>B<hides>($reason)
171
172 Check whether the try stops message which were produced for C<$reason>.
163173
164174 =item $obj-E<gt>B<isDisabled>()
165175
311321
312322 =head1 SEE ALSO
313323
314 This module is part of Log-Report distribution version 1.29,
315 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
324 This module is part of Log-Report distribution version 1.32,
325 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
316326
317327 =head1 LICENSE
318328
319 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
329 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
320330
321331 This program is free software; you can redistribute it and/or modify it
322332 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Dispatcher;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212
1313 use warnings;
394394
395395 =head1 SEE ALSO
396396
397 This module is part of Log-Report distribution version 1.29,
398 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
397 This module is part of Log-Report distribution version 1.32,
398 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
399399
400400 =head1 LICENSE
401401
402 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
402 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
403403
404404 This program is free software; you can redistribute it and/or modify it
405405 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Domain;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'Log::Report::Minimal::Domain';
1313
283283
284284 =head1 SEE ALSO
285285
286 This module is part of Log-Report distribution version 1.29,
287 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
286 This module is part of Log-Report distribution version 1.32,
287 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
288288
289289 =head1 LICENSE
290290
291 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
291 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
292292
293293 This program is free software; you can redistribute it and/or modify it
294294 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Exception;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212
1313 use warnings;
151151
152152 =head1 SEE ALSO
153153
154 This module is part of Log-Report distribution version 1.29,
155 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
154 This module is part of Log-Report distribution version 1.32,
155 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
156156
157157 =head1 LICENSE
158158
159 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
159 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
160160
161161 This program is free software; you can redistribute it and/or modify it
162162 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Message;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212
1313 use warnings;
552552
553553 =head1 SEE ALSO
554554
555 This module is part of Log-Report distribution version 1.29,
556 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
555 This module is part of Log-Report distribution version 1.32,
556 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
557557
558558 =head1 LICENSE
559559
560 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
560 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
561561
562562 This program is free software; you can redistribute it and/or modify it
563563 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report::Translator;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212
1313 use warnings;
6565
6666 =head1 SEE ALSO
6767
68 This module is part of Log-Report distribution version 1.29,
69 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
68 This module is part of Log-Report distribution version 1.32,
69 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
7070
7171 =head1 LICENSE
7272
73 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
73 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
7474
7575 This program is free software; you can redistribute it and/or modify it
7676 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package Log::Report;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use base 'Exporter';
1313
6161
6262 sub report($@)
6363 { my $opts = ref $_[0] eq 'HASH' ? +{ %{ (shift) } } : {};
64 my $reason = shift;
64 my ($reason, $message) = (shift, shift);
65
6566 my $stop = exists $opts->{is_fatal} ? $opts->{is_fatal} : is_fatal $reason;
67 my $try = $nested_tries[-1]; # WARNING: overloaded boolean, use 'defined'
6668
6769 my @disp;
68 if(defined(my $try = $nested_tries[-1]))
70 if(defined $try)
6971 { push @disp, @{$reporter->{needs}{$reason}||[]}
7072 unless $stop || $try->hides($reason);
7173 push @disp, $try if $try->needs($reason);
8183 @disp || $stop
8284 or return;
8385
84 $opts->{errno} ||= $!+0 || $? || 1
85 if use_errno($reason) && !defined $opts->{errno};
86
87 if(my $to = delete $opts->{to})
86 my $to = delete $opts->{to};
87 if($to)
8888 { # explicit destination, still disp may not need it.
8989 if(ref $to eq 'ARRAY')
9090 { my %disp = map +($_->name => $_), @disp;
9393 else
9494 { @disp = grep $_->name eq $to, @disp;
9595 }
96 push @disp, $try if defined $try;
97
9698 @disp || $stop
9799 or return;
98100 }
99101
100 my $message = shift;
102 $opts->{errno} ||= $!+0 || $? || 1
103 if use_errno($reason) && !defined $opts->{errno};
101104
102105 unless(Log::Report::Dispatcher->can('collectLocation'))
103106 { # internal Log::Report error can result in "deep recursions".
127130 $message = $lrm->new(_prepend => $text, @_);
128131 }
129132
130 if(my $to = $message->to)
131 { @disp = grep $_->name eq $to, @disp;
133 $message->to(undef) if $to; # overrule destination of message
134
135 if(my $disp_name = $message->to)
136 { @disp = grep $_->name eq $disp_name, @disp;
137 push @disp, $try if defined $try && $disp_name ne 'try';
132138 @disp or return;
133139 }
134140
11581158
11591159 =head1 SEE ALSO
11601160
1161 This module is part of Log-Report distribution version 1.29,
1162 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
1161 This module is part of Log-Report distribution version 1.32,
1162 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
11631163
11641164 =head1 LICENSE
11651165
1166 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
1166 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
11671167
11681168 This program is free software; you can redistribute it and/or modify it
11691169 under the same terms as Perl itself.
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
77
88 package MojoX::Log::Report;
99 use vars '$VERSION';
10 $VERSION = '1.29';
10 $VERSION = '1.32';
1111
1212 use Mojo::Base 'Mojo::Log'; # implies use strict etc
1313
4848
4949 =head1 SEE ALSO
5050
51 This module is part of Log-Report distribution version 1.29,
52 built on November 08, 2019. Website: F<http://perl.overmeer.net/CPAN/>
51 This module is part of Log-Report distribution version 1.32,
52 built on January 26, 2021. Website: F<http://perl.overmeer.net/CPAN/>
5353
5454 =head1 LICENSE
5555
56 Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
56 Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.
5757
5858 This program is free software; you can redistribute it and/or modify it
5959 under the same terms as Perl itself.
33 use warnings;
44 use strict;
55
6 use Test::More tests => 36;
6 use Test::More;
77
88 use Log::Report undef, syntax => 'SHORT';
99 use Carp; # required for tests
114114 isa_ok($confess_ex, 'Log::Report::Exception');
115115 is($confess_ex->reason, 'PANIC');
116116 like("$@", qr[^try-block stopped with PANIC: oops3 at ] );
117
118 done_testing;
2323 $@ and plan skip_all => 'Unable to load HTTP::Request::Common';
2424 HTTP::Request::Common->import;
2525
26 plan tests => 3;
26 plan tests => 4;
2727 }
2828
2929 {
3939 set logger => 'LogReport';
4040
4141 dispatcher close => 'default';
42
43 hook before => sub {
44 if (query_parameters->get('is_fatal'))
45 {
46 my $foo;
47 $foo->bar;
48 }
49 };
50
51 # Unhandled exception in default route
52 get '/' => sub {
53 my $foo;
54 $foo->bar;
55 };
4256
4357 get '/write_message/:level/:text' => sub {
4458 my $level = param('level');
5569
5670 get '/process' => sub {
5771 process(sub { error "Fatal error text" });
72 };
73
74 get '/show_error/:show_error' => sub {
75 set show_errors => route_parameters->get('show_error');
5876 };
5977
6078 # Route to add custom handlers during later tests
146164 }
147165 };
148166
167 # Tests to check unexpected exceptions
168 subtest 'Unexpected exception default page' => sub {
169
170 # An exception generated from the default route which cannot redirect to
171 # the default route, so it throws a plain text error
172 {
173 my $req = GET "$url/";
174 my $res = $test->request( $req );
175 ok !$res->is_redirect, "No redirect for exception on default route";
176 is $res->content, "An unexpected error has occurred", "Plain text exception text correct";
177 }
178
179 # The same as previous, but this time we enable the development setting
180 # show_error, which means that the content returned is the actual Perl
181 # error string
182 {
183 # First set show_error parameter
184 $test->request(GET "$url/show_error/1");
185 my $req = GET "$url/";
186 my $res = $test->request( $req );
187 ok !$res->is_redirect, "get /write_message";
188 like $res->content, qr/Can't call method "bar" on an undefined value/;
189 # Then set show_error back to disabled
190 $test->request(GET "$url/show_error/0");
191 }
192
193 # This time the exception occurs in an early hook and we are not able to do
194 # anything as the request hasn't been populated yet. Therefore we should
195 # expect Dancer's default error handling
196 {
197 my $req = GET "$url/?is_fatal=1";
198 my $res = $test->request( $req );
199 ok !$res->is_redirect, "get /write_message";
200 like $res->content, qr/Error 500 - Internal Server Error/;
201 }
202 };
203
149204 # Tests to check custom fatal error handlers
150205 subtest 'Custom handler' => sub {
151206
0 # Copyrights 2007-2019 by [Mark Overmeer <markov@cpan.org>].
0 # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>].
11 # For other contributors see ChangeLog.
22 # See the manual pages for details on the licensing terms.
33 # Pod stripped from pm file by OODoc 2.02.
44 package DieTests;
55 use vars '$VERSION';
6 $VERSION = '1.29';
6 $VERSION = '1.32';
77
88 use warnings;
99 use strict;