FlightRecorder - Structured Logging
Logging for Distributed Systems
package main; use FlightRecorder; my $f = FlightRecorder->new( auto => undef ); # $f->begin('try'); # $f->debug('something happened'); # $f->end;
This package provides a simple mechanism for logging events with context, serializing and distributing the event logs, and producing a transcript of activity to provide insight into the behavior of distributed systems.
This package integrates behaviors from:
Data::Object::Role::Pluggable
Data::Object::Role::Throwable
This package uses type constraints from:
Types::Standard
This package has the following attributes:
auto(Maybe[FileHandle])
This attribute is read-only, accepts (Maybe[FileHandle]) values, and is optional.
(Maybe[FileHandle])
format(Str)
This attribute is read-write, accepts (Str) values, and is optional.
(Str)
head(Str)
This attribute is read-only, accepts (Str) values, and is optional.
item(HashRef)
This attribute is read-only, accepts (HashRef) values, and is optional.
(HashRef)
level(Enum[qw(debug info warn error fatal)])
This attribute is read-only, accepts (Enum[qw(debug info warn error fatal)]) values, and is optional.
(Enum[qw(debug info warn error fatal)])
logs(ArrayRef[HashRef])
This attribute is read-only, accepts (ArrayRef[HashRef]) values, and is optional.
(ArrayRef[HashRef])
refs(HashRef)
This package implements the following methods:
begin(Str $label) : Object
The begin method creates and logs a new context.
# given: synopsis $f->begin('test')
branch(Str $label) : Object
The branch method creates and returns a new FlightRecorder object which shares the event log with the parent object. This method creates a new context when called.
# given: synopsis $f->begin('test')->branch('next')
count(Maybe[Str] $level) : Int
The count method returns the total number of log entries, or the number of log entries matching the log level specified.
# given: synopsis $f->begin('try')->debug('something happened')->end; $f->count;
# given: synopsis $f->info('something happened'); $f->count('info');
# given: synopsis $f->fatal('something happened'); $f->count('fatal');
data(HashRef[Str] $data) : Object
The data method associates arbitrary metadata with the last event.
# given: synopsis $f->debug('something happened')->data({ error => 'unknown at ./example line 10' });
debug(Str @message) : Object
The debug method logs a debug level event with context.
debug
# given: synopsis $f->debug('something happened')
end() : Object
The end method logs the end of the current context.
# given: synopsis $f->begin('main')->end
error(Str @message) : Object
The error method logs an error level event with context.
error
# given: synopsis $f->error('something happened')
fatal(Str @message) : Object
The fatal method logs a fatal level event with context.
fatal
# given: synopsis $f->fatal('something happened')
info(Str @message) : Object
The info method logs an info level event with context.
info
# given: synopsis $f->info('something happened')
output(FileHandle $handle) : Str
The output method outputs the last event using the format defined in the format attribute. This method is called automatically after each log-event if the auto attribute is set, which is by default set to STDOUT.
format
auto
STDOUT
# given: synopsis $f->begin('test')->output
package main; use FlightRecorder; my $f = FlightRecorder->new; $f->begin('try'); # $f->output $f->debug('something happened'); # $f->output $f->end; # $f->output
report(Str $name, Str $level) : Object
The report method loads and returns the specified report plugin.
# given: synopsis $f->report('verbose')
# given: synopsis $f->report('succinct', 'fatal')
reset() : Object
The reset method returns an object to its initial state.
# given: synopsis $f->begin('try')->debug('something happened')->end; $f->reset;
# given: synopsis $f->begin('try')->debug('something happened')->end; $f->branch('main')->switch('try')->fatal('something happened')->end; $f->reset;
serialize() : HashRef
The serialize method normalizes and serializes the event log and returns it as a hashref.
hashref
# given: synopsis $f->begin('main')->serialize
simple() : Object
The simple method loads and returns the FlightRecorder::Plugin::ReportSimple report plugin.
# given: synopsis $f->simple
succinct() : Object
The succinct method loads and returns the FlightRecorder::Plugin::ReportSuccinct report plugin.
# given: synopsis $f->succinct
switch(Str $name) : Object
The switch method finds and sets the current context based on the name provided.
# given: synopsis $f->begin('main')->begin('test')->switch('main')
verbose() : Object
The verbose method loads and returns the FlightRecorder::Plugin::ReportVerbose report plugin.
# given: synopsis $f->verbose
warn(Str @message) : Object
The warn method logs a warn level event with context.
warn
# given: synopsis $f->warn('something happened')
Al Newkirk, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2011-2019, Al Newkirk, et al.
This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".
Wiki
Project
Initiatives
Milestones
Contributing
Issues
To install FlightRecorder, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FlightRecorder
CPAN shell
perl -MCPAN -e shell install FlightRecorder
For more information on module installation, please visit the detailed CPAN module installation guide.