Mojo::Log::JSON::LogStash - Simple JSON logger to produce LogStash format logs
package MyApp; use Mojo::Log::JSON::LogStash; sub startup { my $self = shift; ... open my $handle, '|-', 'logstash-forwarder -config=/path/to/logstash-forwarder-config.conf' or die "can't run logstash-forwarder: $!"; my $logger = Mojo::Log::JSON::LogStash->new( handle => $handle ); $logger->default_fields->{foo} = "bar"; # add extra default field ... } # Log messages - debug, info, warn, error, fatal (same as Mojo::Log) $log->debug( "A simple string" ); $log->debug( "A", "message", "over", "multiple", "lines" ); $log->debug( { message => "A data structure", foo => "bar" } ); # The above examples would generate something like the following: {"@timestamp":"2014-03-13T13:15:44.005134Z","@version":1,"level":"debug","message":"A simple string"} {"@timestamp":"2014-03-13T13:15:45.123565Z","@version":1,"level":"debug","message":"A\nmessage\nover\nmultiple\nlines"} {"@timestamp":"2014-03-13T13:15:46.863454Z","@version":1,"foo":"bar","level":"debug","message":"A data structure"}
Mojo::Log::JSON::LogStash is a simple subclass of Mojo::Log::JSON to produce JSON logs suitable for LogStash.
The key level is always added to the data structure, with the value set to the level of the log message being emitted.
level
The required LogStash keys @timestamp and @version are also added to the data structure. @timestamp is set with a value of the current time in UTC in ISO 8601 format, with microseconds.
@timestamp
@version
These can be overridden or other fields added via the default_fields attributes.
default_fields
See Mojo::Log::JSON.
Please report any bugs or feature requests through the issue tracker at https://github.com/mjemmeson/mojo-log-json/issues. You will be notified automatically of any progress on your issue.
This is open source software. The code repository is available for public review and contribution under the terms of the license.
https://github.com/mjemmeson/mojo-log-json
git clone git://github.com/mjemmeson/mojo-log-json.git
Michael Jemmeson <mjemmeson@cpan.org>
Copyright 2014- Michael Jemmeson
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Mojo::Log::JSON, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Log::JSON
CPAN shell
perl -MCPAN -e shell install Mojo::Log::JSON
For more information on module installation, please visit the detailed CPAN module installation guide.