Skip to content

Commit

Permalink
Merge branch 'docs/missing-log-info'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason A. Crome committed Jan 3, 2024
2 parents 4bcfd04 + 1be1466 commit 850dd2b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
{{$NEXT}}

[ BUG FIXES ]
* None

[ ENHANCEMENTS ]
* GH #33: Named routes; add uri_for_route keyword (Sawyer X)

[ DOCUMENTATION ]
* PR #1706: Document missing logging hooks and log format option;
fix typo in logging test (Jason A. Crome)

[ DEPRECATED ]
* None

[ MISC ]
* None

1.1.0 2023-12-11 20:28:26-05:00 America/New_York

[ BUG FIXES ]
Expand Down
4 changes: 4 additions & 0 deletions lib/Dancer2/Core/Role/Logger.pm
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ The possible values are:
=over 4
=item %a
app name
=item %h
host emitting the request
Expand Down
29 changes: 29 additions & 0 deletions lib/Dancer2/Manual.pod
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,35 @@ for details on the following hooks:

=back

=head2 Logging

Logging hooks do not allow you to alter log message content, but they do
give you a place to perform extra actions. For example, if you want to send
an email for error messages, but you don't want to use a heavier logger
such as L<Log::Any> or L<Log::Log4perl>:

hook 'engine.logger.after' => sub {
my ( $logger, $level, $message ) = @_;

if( $level eq 'error' ) {
# Send an email with the message content
}
};

There are two hooks available for logging:

=over 4

=item * engine.logger.before

This hook is called before a log message is produced.

=item * engine.logger.after

This hook is called after a log message is produced.

=back

=head2 Serializers

=over 4
Expand Down
2 changes: 1 addition & 1 deletion t/logger.t
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ subtest 'log level and capture' => sub {
is_deeply $trap->read, [];
};

subtest 'logger enging hooks' => sub {
subtest 'logger engine hooks' => sub {
# before hook can change log level or message.
hook 'engine.logger.before' => sub {
my $logger = shift; # @_ = ( $level, @message_args )
Expand Down

0 comments on commit 850dd2b

Please sign in to comment.