NAME
Cache::Memcached::Fast::Logger - the simple logger object for writing and reading all log items to/from memcached
SYNOPSIS
my $logger = Cache::Memcached::Fast::Logger->new( cache => Cache::Memcached::Fast->new(...) );
# one or more processes log items to memcached like this:
$logger->log( { key1 => 'value1', keys2 => 'value2' } );
# Other process - a parser of logs items reads all items by:
$logger->read_all( sub { $item = shift; ... ; 1 } );
DESCRIPTION
Why this module? Sometime i need in helper for logging and parsing some statistics. To write in file a logs for parsing is very bad idea - I/O of HDD is very slow.
With this module many concurrent proccesses can write to memcached by "log" method and one process (for example a parser of logs) can read all logs in FIFO order from memcached by "read_all" method. This module is simple and it uses atomic "incr" in Cache::Memcached::Fast & "cas" in Cache::Memcached::Fast memcached's protocol methods (for internal counter of queue) for guarantee that all your items will not be lost during write phase in memcached (memcached doesn't guarantee a data keeping but if your cache has an enough free slabs you will not lose your log items)
CONSTRUCTOR
my $logger = Cache::Memcached::Fast::Logger->new( cache => $cache )
Only cache option used and should be instance of Cache::Memcached::Fast object. All options of memcached specific features should be defined by creation of Cache::Memcached::Fast instance.
METHODS
- log( $log_item )
-
$log_item
cab be scalar, hashref or arrayref. It's serialized by Cache::Memcached::Fast. - read_all( $cb )
-
$cb
is callback function (parser of one log item). It is called (by this way$cb->( $log_item )
) for every item of log item written to memcached. This function should be returntrue
to continue a parsing andfalse
if callback wants to terminate a log reading proccess (if it catched a TERM signal for example). This method is executed to complete reading log items in memcached.
NOTES
This module uses a following keys for log items: log_counter & log_N, where N is positive number from 0 to max integer of perl. You can use "namespace" in Cache::Memcached::Fast option or method to isolate these keys from your other keys.
AUTHOR
This module has been written by Perlover <perlover@perlover.com>, 2012 year
LICENSE
This module is free software and is published under the same terms as Perl itself.