EventSource
NAME
Lumberjack::Dispatcher::EventSource - dispatch Lumberjack messages to server sent events
SYNOPSIS
use Lumberjack;
use Lumberjack::Dispatcher::EventSource;
use Cro::HTTP::Router;
use Cro::HTTP::Server;
my $dispatcher = Lumberjack::Dispatcher::EventSource.new
Lumberjack.dispatchers.append: $dispatcher;
my $app = route {
get -> {
content 'text/event-stream', $dispatcher.Supply;
}
};
my Cro::Service $log = Cro::HTTP::Server.new(:host<localhost>, :port<7798>, application => $app);
$log.start;
react whenever signal(SIGINT) { $log.stop; exit; }
DESCRIPTION
This is a Lumberjack::Dispatcher
implementation that emits the log messages as JSON (as formatted by
Lumberjack::Message::JSON
,) on a supply in the format of Server Sent Events.
The Supply
can be passed as a response to a web toolkit that supports chunked encoding such as Cro
or Crust
.
This may be useful if you want to expose your logging to the web or to some log archover or something.
The exact format of the JSON emitted is documented by Lumberjack::Message::JSON
METHODS
method new
method new()
This takes the classes
and levels
parameters that are provided for by Lumberjack::Dispatcher
and constraint the messages that are handled but has no other useful parameters.
attribute Supply
This is the Supply
to which the messages will be emitted. In some places this will be used as a coercion so the object itself can be passed.