Build Status

NAME

Log::Dispatch::Gelf - Log::Dispatch plugin for Graylog's GELF format.

SYNOPSIS

use Log::Dispatch;

my $sender = ... # e.g. RabbitMQ queue.
my $log = Log::Dispatch->new(
    outputs => [
        #some custom sender
        [
            'Gelf',
            min_level         => 'debug',
            additional_fields => { facility => __FILE__ },
            send_sub          => sub { $sender->send($_[0]) },
        ],
        #or send to graylog via TCP/UDP socket
        [
            'Gelf',
            min_level         => 'debug',
            additional_fields => { facility => __FILE__ },
            socket            => {
                host     => 'graylog.server',
                port     => 21234,
                protocol => 'tcp',
            }
        ],
        # define callback to crop your full message to short in your own way
        [
            'Gelf',
            min_level         => 'debug',
            additional_fields => { facility => __FILE__ },
            send_sub          => sub { $sender->send($_[0]) },
            short_message_sub => sub { substr($_[0], 0, 10) }
        ],
    ],
);
$log->info('It works');

$log->log(
    level             => 'info',
    message           => "It works\nMore details.",
    additional_fields => { test => 1 }
);

DESCRIPTION

Log::Dispatch::Gelf is a Log::Dispatch plugin which formats the log message according to Graylog's GELF Format version 1.1. It supports sending via a socket (TCP or UDP) or a user provided sender.

CONSTRUCTOR

The constructor takes the following parameters in addition to the standard parameters documented in Log::Dispatch::Output:

METHODS

$log->log( level => $, message => $, additional_fields => \% )

In addition to the corresponding method in Log::Dispatch::Output this subclassed method takes an optional hashref of additional_fields for the gelf message. As in the corresponding parameter on the constructor there is no need to prefix them with an _. If the same key appears in both the constructor's and method's additional_fields then the method's value will take precedence overriding the constructor's value for the current call.

The subclassed log method is still called with all parameters passed on.

LICENSE

Copyright (C) Avast Software.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Miroslav Tynovsky tynovsky@avast.com