NAME

Timed::Logger - store events for later analysis.

VERSION

Version 0.0.5

SYNOPSIS

use Timed::Logger;

my $logger = Timed::Logger->new;

my $log_entry = $logger->start;
#...
#some lengthly operation
#...
$logger->finish($entry, { description => 'long operation' });

#...

foreach my $entry ($logger->log->{default}) {
    printf("Operation %s took $.4f s", $entry->data->{description}, $entry->elapsed);
}

printf("Total time: $.4f s", $logger->elapsed_total);
printf("Total time in default bucket: $.4f s", $logger->elapsed_total('default'));

DESCRIPTION

Timed::Logger allows one to log events along with amount if time that event took. This can be useful for debugging and profiling purposes. See Plack::Middleware::Debug::Timed::Logger for usage example.

BUCKETS

Sometimes you want to break your events into different types and anaylze them separately. This can be achieved using buckets:

my $log_entry = $logger->start('DB');
#...
#some DB operation
#...
$logger->finish($entry, { description => 'long operation' });

my $log_entry = $logger->start('some');
#...
#some other type of operation
#...
$logger->finish($entry, { description => 'long operation' });

By default bucket named 'default' is used.

ATTRIBUTES

log

This attribute contains a log gathered so far. It is organized as an hashref of arrayref of entries. Keys in a hash represent buckets. Each entry has a Timed::Logger::Entry type.

METHODS

new

Create a new Timed::Logger.

start([$bucket])

Start a new event. Returns new Timed::Logger::Entry. One can specify bucket to use, otherwise 'default' is used.

finish($entry[, $data])

Save current into log. If optional $data is set it is stored in Timed::Logger::Entry data attribute.

elapsed_total([$bucket])

Calculates total time for all events (by default) or for given bucket if one is provided.

SEE ALSO

Plack::Middleware::Timed::Logger, Plack::Middleware::Debug::Timed::Logger, Timed::Logger::Dancer::AdoptPlack

AUTHOR

Nikolay Martynov, <kolya at cpan.org>

BUGS

Please report any bugs or feature requests to bug-timed-logger at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Timed-Logger. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Timed::Logger

You can also look for information at:

ACKNOWLEDGEMENTS

Logan Bell and Belden Lyman.

LICENSE AND COPYRIGHT

Copyright 2013 Nikolay Martynov and Shutterstock Inc (http://shutterstock.com). All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.