Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A very simple JSON logger

branch: master

v0.001

    * Initial release.
latest commit ad781c02fa
Eric Johnson authored April 29, 2012
Octocat-spinner-32 lib Fix Pod::Coverage complaints. April 29, 2012
Octocat-spinner-32 t Initial commit. April 14, 2012
Octocat-spinner-32 .gitignore Ignore builds. April 29, 2012
Octocat-spinner-32 Changes Initial release. April 29, 2012
Octocat-spinner-32 META.json Changes caused by upgrading Dist::Zilla. April 29, 2012
Octocat-spinner-32 README.pod Updates. April 29, 2012
Octocat-spinner-32 dist.ini v0.001 April 29, 2012
README.pod

NAME

Log::JSON - Log data to a file as JSON

SYNOPSIS

    use Log::JSON;
    my $logger = Log::JSON->new(
        file            => '/path/errorlog.json', # required
        date            => 1, # optional
        remove_newlines => 1, # optional
    );
    $logger->log(a => 1, b => 2);
    # '/path/errorlog.json' now contains: 
    # {"__date":"2010-03-28T23:15:52Z","a":1,"b":1}

DESCRIPTION

This module logs a hash to a file as JSON. The keys are printed in sorted order.

Often log files have several raw numbers and strings whose meaning is not immediately clear. With JSON formatted text in your log files, a human can open the file and quickly decipher the content because each piece of information is labeled.

Using JSON also means log files are easy to parse and the data structures can be easily revived.

ATTRIBUTES

date

Adds an __date field to your json. The '__' part ensures the date is the first information logged to each line when the keys are sorted.

file

The name of the file to log data to

remove_newlines

This boolean is set to true by default. It means your json data structures will be logged entirely on one line.

METHODS

log(%hash)

Appends %hash to a file as JSON. The keys are sorted when the hash is converted to JSON.

BUGS

This should probably should have been a Log::Dispatch plugin.

SEE ALSO

Log::Message::Structured, Log::Structured, Log::Sprintf

THANKS

Thanks to Foxtons Ltd for providing the opportunity to write and release the original version of this module.

AUTHOR

Eric Johnson <cpan at iijo dot org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Eric Johnson.

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

Something went wrong with that request. Please try again.