Last active
February 1, 2017 22:44
-
-
Save jberger/961dbf907c7e62586542d7317043014b to your computer and use it in GitHub Desktop.
Using syslog in a mojo app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MyApp; | |
use Mojo::Base 'Mojolicious'; | |
use Log::Dispatch; | |
sub setup { | |
my $self = shift; | |
... | |
# Setup syslog logging | |
my $ident = 'some identity string'; | |
$self->log->on( 'message' => sub { | |
my ( undef, $level, @lines ) = @_; | |
state $dispatch = Log::Dispatch->new( | |
outputs => [ | |
[ | |
'Syslog', | |
min_level => 'debug', | |
facility => 'local0', | |
ident => $ident, | |
], | |
], | |
); | |
for my $line ( @lines ) { | |
$dispatch->log( level => $level, message => "$line" ); | |
} | |
} ); | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment