Imported Upstream version 0.03

This commit is contained in:
Mario Fetka 2018-02-16 16:07:18 +01:00
commit 03893a2309
15 changed files with 487 additions and 0 deletions

7
Changes Normal file
View File

@ -0,0 +1,7 @@
Revision history for Log-Log4perl-Layout-GELF
0.02 2011-07-19 12:00
Fixed dependencies and test files
0.01 2011-07-19 08:00
First version, released on an unsuspecting world.

15
MANIFEST Normal file
View File

@ -0,0 +1,15 @@
Changes
ignore.txt
lib/Log/Log4perl/Layout/GELF.pm
Makefile.PL
MANIFEST This list of files
README
README.md
t/00-init.t
t/01-log_to_graylog.t
t/02-log_to_screen.t
t/manifest.t
t/pod-coverage.t
t/pod.t
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)

44
META.json Normal file
View File

@ -0,0 +1,44 @@
{
"abstract" : "Log4perl for graylog2",
"author" : [
"Jason Pope <cowholio4@gmail.com>"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 6.59, CPAN::Meta::Converter version 2.112150",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "Log-Log4perl-Layout-GELF",
"no_index" : {
"directory" : [
"t",
"inc"
]
},
"prereqs" : {
"build" : {
"requires" : {
"ExtUtils::MakeMaker" : 0
}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : 0
}
},
"runtime" : {
"requires" : {
"IO::Compress::Gzip" : "2.00",
"JSON::XS" : "2.30",
"Log::Log4perl" : "1.33",
"Test::More" : 0
}
}
},
"release_status" : "stable",
"version" : "0.03"
}

25
META.yml Normal file
View File

@ -0,0 +1,25 @@
---
abstract: 'Log4perl for graylog2'
author:
- 'Jason Pope <cowholio4@gmail.com>'
build_requires:
ExtUtils::MakeMaker: 0
configure_requires:
ExtUtils::MakeMaker: 0
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.59, CPAN::Meta::Converter version 2.112150'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Log-Log4perl-Layout-GELF
no_index:
directory:
- t
- inc
requires:
IO::Compress::Gzip: 2.00
JSON::XS: 2.30
Log::Log4perl: 1.33
Test::More: 0
version: 0.03

23
Makefile.PL Normal file
View File

@ -0,0 +1,23 @@
use 5.006;
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Log::Log4perl::Layout::GELF',
AUTHOR => q{Jason Pope <cowholio4@gmail.com>},
VERSION_FROM => 'lib/Log/Log4perl/Layout/GELF.pm',
ABSTRACT_FROM => 'lib/Log/Log4perl/Layout/GELF.pm',
($ExtUtils::MakeMaker::VERSION >= 6.3002
? ('LICENSE'=> 'perl')
: ()),
PL_FILES => {},
PREREQ_PM => {
'Test::More' => '0',
'JSON::XS' => '2.30',
'IO::Compress::Gzip' => '2.00',
'Log::Log4perl' => '1.33'
},
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
clean => { FILES => 'Log-Log4perl-Layout-GELF-*' },
);

55
README Normal file
View File

@ -0,0 +1,55 @@
Log-Log4perl-Layout-GELF
The README is used to introduce the module and provide instructions on
how to install the module, any machine dependencies it may have (for
example C compilers and installed libraries) and any other information
that should be provided before the module is installed.
A README file is required for CPAN modules since CPAN extracts the README
file from a module distribution so that people browsing the archive
can use it to get an idea of the module's uses. It is usually a good idea
to provide version information here so that people can decide whether
fixes for the module are worth downloading.
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
make
make test
make install
SUPPORT AND DOCUMENTATION
After installing, you can find documentation for this module with the
perldoc command.
perldoc Log::Log4perl::Layout::GELF
You can also look for information at:
RT, CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Log-Log4perl-Layout-GELF
AnnoCPAN, Annotated CPAN documentation
http://annocpan.org/dist/Log-Log4perl-Layout-GELF
CPAN Ratings
http://cpanratings.perl.org/d/Log-Log4perl-Layout-GELF
Search CPAN
http://search.cpan.org/dist/Log-Log4perl-Layout-GELF/
LICENSE AND COPYRIGHT
Copyright (C) 2011 Jason Pope
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.

9
README.md Normal file
View File

@ -0,0 +1,9 @@
Log::Log4perl::Layout::GELF (Log4perl in graylog format)
========================================================================
## Summary
[Log4perl]("http://search.cpan.org/~mschilli/Log-Log4perl-1.33/lib/Log/Log4perl.pm")
is great. [Graylog]("http://graylog2.org/") is awesome. This layout when used with
Log::Log4perl::Appender::Socket allows you to log directly to graylog.

12
ignore.txt Normal file
View File

@ -0,0 +1,12 @@
blib*
Makefile
Makefile.old
Build
Build.bat
_build*
pm_to_blib*
*.tar.gz
.lwpcookies
cover_db
pod2htm*.tmp
Log-Log4perl-Layout-GELF-*

View File

@ -0,0 +1,165 @@
##################################################
package Log::Log4perl::Layout::GELF;
##################################################
use 5.006;
use strict;
use warnings;
use JSON::XS;
use IO::Compress::Gzip qw( gzip $GzipError );
use Log::Log4perl;
use base qw(Log::Log4perl::Layout::PatternLayout);
# We need to define our own cspecs
$Log::Log4perl::ALLOW_CODE_IN_CONFIG_FILE = 1;
=head1 NAME
Log::Log4perl::Layout::GELF - Log4perl for graylog2
=head1 VERSION
Version 0.03
=cut
our $VERSION = '0.03';
=head1 SYNOPSIS
Log4perl implementation of GELF. When used with
Log::Log4perl::Appender::Socket you can log directly
to a graylog2 server.
=cut
=head1 What is graylog?
Graylog is log management server that can be used to run analytics,
alerting, monitoring and perform powerful searches over your whole
log base. Need to debug a failing request? Just run a quick filter
search to find it and see what errors it produced. Want to see all
messages a certain API consumer is consuming in real time? Create
streams for every consumer and have them always only one click away.
=cut
=head1 Configuration Sample
Code snippet. Replace the ip with your graylog server.
use Log::Log4perl
my $logger_conf = {
'log4perl.logger.graylog' => "DEBUG, SERVER",
'log4perl.appender.SERVER' => "Log::Log4perl::Appender::Socket",
'log4perl.appender.SERVER.PeerAddr' => '10.211.1.94',
'log4perl.appender.SERVER.PeerPort' => "12201",
'log4perl.appender.SERVER.Proto' => "udp",
'log4perl.appender.SERVER.layout' => "GELF"
};
Log::Log4perl->init( $logger_conf );
my $LOGGER = Log::Log4perl->get_logger('graylog');
$LOGGER->debug("Debug log");
...
=cut
=head1 SUBROUTINES/METHODS
=head2 new
Can take most of options that Log::Log4perl::Layout::PatternLayout can.
Additional Options:
PlainText - outputs plaintext and not gzipped files.
=cut
sub new {
my $class = shift;
$class = ref ($class) || $class;
my $options = ref $_[0] eq "HASH" ? shift : {};
# Creating object to make changes easier
my $gelf_format = {
"version" => "1.0",
"host" => "%H",
"short_message" => "%m{chomp}",
"timestamp" => "%Z", # custom cspec
"level"=> "%Y", # custom cspec
"facility"=> "%M",
"file"=> "%F",
"line"=> "%L",
"_pid" => "%P",
};
# make a JSON string
my $conversion_pattern = encode_json($gelf_format);
$options->{ConversionPattern} = { value => $conversion_pattern } ;
# Since we are building on top of PatternLayout, we can define our own
# own patterns using a "cspec".
$options->{cspec} = {
'Z' => { value => sub {return time } },
'Y' => { value => \&_level_converter } ,
};
my $self = $class->SUPER::new($options);
# to help with debugging. you can skip the bzipping.
$self->{PlainText} = 0;
if(defined $options->{PlainText}->{value} ){
$self->{PlainText} = $options->{PlainText}->{value};
}
return $self;
}
# Maps over the syslog levels from Log4perl levels.
# Syslog Levels for Reference
# 0 Emergency: system is unusable
# 1 Alert: action must be taken immediately
# 2 Critical: critical conditions
# 3 Error: error conditions
# 4 Warning: warning conditions
# 5 Notice: normal but significant condition
# 6 Informational: informational messages
# 7 Debug: debug-level messages
sub _level_converter {
my ($layout, $message, $category, $priority, $caller_level) = @_;
# TODO Replace with a case statement
my $levels = {
"DEBUG" => 7,
"INFO" => 6,
"NOTICE"=> 5,
"WARN" => 4,
"ERROR" => 3,
"FATAL" => 2
};
return $levels->{$priority};
}
=head2 render
Wraps the Log::Log4perl::Layout::PatternLayout return value so we can
gzip the JSON string.
=cut
sub render {
my($self, $message, $category, $priority, $caller_level) = @_;
my $encoded_message = $self->SUPER::render($message, $category, $priority, $caller_level);
# makes debugging easier
if( defined $self->{PlainText} && $self->{PlainText} ){
return $encoded_message;
}
# Graylog2 servers require gzipped messesages.
my $gzipped_message;
gzip \$encoded_message => \$gzipped_message or die "gzip failed: $GzipError\n";
return $gzipped_message;
}
1;

13
t/00-init.t Normal file
View File

@ -0,0 +1,13 @@
#!perl -T
use strict;
use warnings;
use Test::More tests => 3;
BEGIN { use_ok( 'Log::Log4perl::Layout::GELF' ); }
my $layout = Log::Log4perl::Layout::GELF->new();
isa_ok($layout, "Log::Log4perl::Layout::GELF");
can_ok($layout, ("render"));

42
t/01-log_to_graylog.t Normal file
View File

@ -0,0 +1,42 @@
#!perl -T
use strict;
use warnings;
use Test::More tests => 4;
BEGIN { use_ok( 'Log::Log4perl::Layout::GELF' ); }
BEGIN { use_ok( 'Log::Log4perl' ); }
my $layout = Log::Log4perl::Layout::GELF->new();
isa_ok($layout, "Log::Log4perl::Layout::GELF");
can_ok($layout, ("render"));
_init_logger();
sub _init_logger
{
my %logger_conf = (
'log4perl.logger.test.screen' => "DEBUG, DEFAULT",
'log4perl.appender.DEFAULT' => "Log::Log4perl::Appender::Screen",
'log4perl.appender.DEFAULT.stderr' => "0",
'log4perl.appender.DEFAULT.layout' => "GELF",
'log4perl.logger.test.server' => "DEBUG, SERVER",
'log4perl.appender.SERVER' => "Log::Log4perl::Appender::Socket",
'log4perl.appender.SERVER.PeerAddr' => '10.211.1.94',
'log4perl.appender.SERVER.PeerPort' => "12201",
'log4perl.appender.SERVER.Proto' => "udp",
'log4perl.appender.SERVER.layout' => "GELF"
);
Log::Log4perl->init( \%logger_conf );
my $LOGGER = Log::Log4perl->get_logger('test.server');
$LOGGER->debug("debug test");
$LOGGER->error("error test");
$LOGGER->info("info test");
$LOGGER->warn("warn test");
$LOGGER->fatal("fatal test");
}

34
t/02-log_to_screen.t Normal file
View File

@ -0,0 +1,34 @@
#!perl -T
use strict;
use warnings;
use Test::More tests => 2;
BEGIN { use_ok( 'Log::Log4perl::Layout::GELF' ); }
BEGIN { use_ok( 'Log::Log4perl' ); }
_init_logger();
sub _init_logger
{
my %logger_conf = (
'log4perl.logger.test.screen' => "DEBUG, DEFAULT",
'log4perl.appender.DEFAULT' => "Log::Log4perl::Appender::Screen",
'log4perl.appender.DEFAULT.stderr' => "0",
'log4perl.appender.DEFAULT.layout' => "GELF",
'log4perl.appender.DEFAULT.layout.PlainText' => "1",
);
Log::Log4perl->init( \%logger_conf );
my $LOGGER = Log::Log4perl->get_logger('test.screen');
$LOGGER->debug("debug test");
$LOGGER->error("error test");
$LOGGER->info("info test");
$LOGGER->warn("warn test");
$LOGGER->fatal("fatal test");
}

13
t/manifest.t Normal file
View File

@ -0,0 +1,13 @@
#!perl -T
use strict;
use warnings;
use Test::More;
unless ( $ENV{RELEASE_TESTING} ) {
plan( skip_all => "Author tests not required for installation" );
}
eval "use Test::CheckManifest 0.9";
plan skip_all => "Test::CheckManifest 0.9 required" if $@;
ok_manifest();

18
t/pod-coverage.t Normal file
View File

@ -0,0 +1,18 @@
use strict;
use warnings;
use Test::More;
# Ensure a recent version of Test::Pod::Coverage
my $min_tpc = 1.08;
eval "use Test::Pod::Coverage $min_tpc";
plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
if $@;
# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
# but older versions don't recognize some common documentation styles
my $min_pc = 0.18;
eval "use Pod::Coverage $min_pc";
plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
if $@;
all_pod_coverage_ok();

12
t/pod.t Normal file
View File

@ -0,0 +1,12 @@
#!perl -T
use strict;
use warnings;
use Test::More;
# Ensure a recent version of Test::Pod
my $min_tp = 1.22;
eval "use Test::Pod $min_tp";
plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
all_pod_files_ok();