Skip to content

Instantly share code, notes, and snippets.

@jberger
Last active February 1, 2017 22:44
Show Gist options
  • Save jberger/961dbf907c7e62586542d7317043014b to your computer and use it in GitHub Desktop.
Save jberger/961dbf907c7e62586542d7317043014b to your computer and use it in GitHub Desktop.
Using syslog in a mojo app
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