Git Product home page Git Product logo

log-dispatch-gelf's Introduction

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:

  • additional_fields

    optional hashref of additional fields of the gelf message (no need to prefix them with _, the prefixing is done automatically).

  • chunked

    optional scalar. An integer specifying the chunk size or the special string values 'lan' or 'wan' corresponding to 8154 or 1420 respectively. A zero chunk size means no chunking will be applied.

    Chunking is only applicable to UDP connections.

  • compress

    optional scalar. If a true value the message will be gzipped with IO::Compress::Gzip.

  • send_sub

    mandatory sub for sending the message to graylog. It is triggered after the gelf message is generated.

  • short_message_sub

    sub for code that will crop your full message to short message. By default it deletes everything after first newline character

  • socket

    optional hashref create tcp or udp (default behavior) socket and set send_sub to sending via socket

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 [email protected]

log-dispatch-gelf's People

Contributors

adamc00 avatar tynovsky avatar alexrkopp avatar luckamohelnikova avatar doojonio avatar jasei avatar

Stargazers

 avatar  avatar Ilya avatar Mike Lutz avatar

Watchers

Tomáš Procházka avatar  avatar  avatar Alena Varkockova avatar Michal Augustýn avatar Tomas Vondracek avatar James Cloos avatar Vít Heřman avatar Galina Alperovich avatar  avatar Lukáš Kučera avatar  avatar  avatar Michal Trs avatar Rudolf Pliva avatar Karel Fajkus avatar  avatar  avatar

log-dispatch-gelf's Issues

Perl 5.14 regex syntax breaking older perl version

Hello,

Version 1.4.0 broke support for perl versions older than 5.14.

A regex flag introduced in Perl 5.14 has been used here

$ perl -v 
This is perl, v5.10.1 (*) built for x86_64-linux 
Bareword found where operator expected at /app/t/../local/lib/perl5/Log/Dispatch/Gelf.pm line 86, near "s/\n.*//sr"

Fix would be to find a 5.10 compatible option or drop support and advertise 5.14+ support in Meta.json and cpanfile.

Thanks !

t/02_socket.t may fail (with recent JSON::XS?)

On some of my smokers the test suite fails:

garbage after JSON object, at character offset 152 (before "(end of string)") at t/02_socket.t line 188.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 2 just after 15.
t/02_socket.t ...... 
Dubious, test returned 2 (wstat 512, 0x200)
All 15 subtests passed 

This seems to happen if recent JSON::XS (4.02 or so) is installed.

log via tcp socket doesn't work

config of tcp gelf input:

recv_buffer_size: 1048576
port: 12201
tls_key_file:
tls_key_password: *******
use_null_delimiter: true
tcp_keepalive: true
tls_client_auth_cert_file:
max_message_size: 2097152
tls_client_auth: disabled
override_source:
bind_address: 0.0.0.0
tls_cert_file:

and publish via

#!/usr/bin/env perl
use strict;
use warnings;
use Log::Dispatch;

my $log = Log::Dispatch->new(
    outputs => [
        [
            'Gelf',
            min_level         => 'debug',
            additional_fields => { facility => 'test' },
            socket            => {
                host     => 'sealion.srv.int.avast.com',
                port     => 12201,
                protocol => 'tcp',
            }
        ]
    ],
);
$log->info('It works');

doesn't works;)

but if I replace tcp to udp - then loggging works

sending utf-8 string through socket raises an error

Calling a line like this

$log->info("მინას");

raises an error like this

Wide character in send at /.../perl-5.24.1/lib/5.24.1/x86_64-linux/IO/Socket.pm line 286.

We could add an option of binmode to the socket created for sending logs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.