Skip to content

Instantly share code, notes, and snippets.

@mjemmeson
Created January 30, 2014 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjemmeson/8705760 to your computer and use it in GitHub Desktop.
Save mjemmeson/8705760 to your computer and use it in GitHub Desktop.
package Mojo::Log::JSON;
use Mojo::Base 'Mojo::Log';
use HTTP::Date qw/ time2iso /;
use JSON qw/ to_json /;
sub format {
my ( $self, $level, @lines ) = @_;
my %msg = (
ref $lines[0] #
? %{ $lines[0] } #
: ( message => join( "\n", @lines ) ),
level => $level,
datetime => time2iso(),
);
return to_json( \%msg, { utf8 => 1, canonical => 1 } ) . "\n";
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment