NAME
OP::Log
DESCRIPTION
Create and access message sinks on the fly. By default, message sinks are circular OP::RRNode tables.
This class may be used directly, or subclassed for a specific application.
INHERITANCE
This class inherits additional class and object methods from the following packages:
OP::Class > OP::Object > OP::Hash > OP::Node > OP::Log
Circular table classes are derived from OP::RRNode.
SYNOPSIS
First, the log needs to be defined in MySQL as a writable datasource:
use strict;
use warnings;
use OP::Log;
sub createLog {
my $log = OP::Log->spawn("Alex's Log");
$log->setNumRows(10);
$log->save();
}
createLog();
Callers may then write to it:
use strict;
use warnings;
use OP::Log;
my $log = OP::Log->spawn("Alex's Log");
$log->write("Writing something");
...or record numeric values:
my $log = OP::Log->spawn("Ben's Log");
$log->record(432.234);
If more control is needed when saving messages, full object access is available:
...
use OP::Log;
my $log = OP::Log->spawn("Alex's Log");
my $message = $log->newMessage();
$message->setMessage("Testing at " . scalar(localtime()));
$message->setState( OP::Enum::State::Crit );
$message->setValue($$);
$message->setTimestamp(time());
$message->save();
The instance method messageClass()
returns a OP::RRNode subclass, a handle for the actual stored messages.
...
my $log = OP::Log->spawn( ... );
#
# messageClass() returns the message sink table:
#
my $table = $log->messageClass();
for my $id ( $table->allIds() ) {
my $message = $table->load($id);
$message->print();
}
Time Series Data
Time series data is directly available through the series()
instance method. This method returns an OP::Series object.
...
my $log = OP::Log->spawn( ... );
#
# Get interpolated time series data, ie { unixtime => value, ... }
#
my $series = $log->series($start,$end);
my $data = $series->cooked();
$data->each( sub {
print "At unix time $_, the value was $series->{$_}.\n";
} );
SEE ALSO
This file is part of OP.
REVISION
$Id: //depotit/tools/source/snitchd-0.20/lib/OP/Log.pm#7 $