JSON

NAME

Lumberjack::Message::JSON - role to allow Lumberjack::Message to serialise/deserialise as JSON

SYNOPSIS


use Lumberjack;
use Lumberjack::Message::JSON;

my $message = Lumberjack::Message.new(message => 'this is a message');
$message does Lumberjack::Message::JSON;

my $str = $message.to-json;

...

my $new-message = (Lumberjack::Message but Lumberjack::Message::JSON).from-json($str);

# Alternatively the derived type can be provided as a constant:

constant JSONMessage = (Lumberjack::Message but Lumberjack::Message::JSON);

...

DESCRIPTION

This is used by Lumberjack::Dispatcher::EventSource, Lumberjack::Dispatcher::Proxy, Lumberjack::Application::PSGI and Lumberjack::Application::WebSocket to serialise and deserialise the Lumberjack::Message to/from JSON for transport over HTTP or websockets.

It is implemented as role that can be mixed at run-time to existing Message objects and to create a derived type to un-marshal to (see the SYNOPSIS.)

Itself it uses JSON::Class to provide to-json and from-json and provides custom marshallers and un-marshallers to ensure that the data is rendered meaningfully in JSON.

The JSON will be something like:

{
   "backtrace" : [
      {
         "file" : "-e",
         "line" : 1,
         "subname" : "<unit>",
         "code" : {}
      }
   ],
   "message" : "this is a test",
   "class" : {
      "log-level" : 2,
      "is-logger" : false,
      "name" : "Any"
   },
   "level" : 2,
   "when" : "2016-04-12T00:18:34.435650+01:00"
}

Which reflects the Lumberjack::Message fairly closely. There may of course be more backtrace frames.

The 'class' object in the JSON when de-serialised may cause a temporary type to be created with the name provided if the type is not available on the target system, if "is-logger" is true then it will have the Lumberjack::Logger applied and the log-level set. This is done so that the message will appear the same as one created on the local system for a message received from a remote logger.

Lumberjack::Message::JSON v0.1.10

Lumberjack::Message represented as JSON

Authors

  • Jonathan Stowe

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • Lumberjack::Message::JSON

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.