NAME

EntityModel::Log - simple logging support for EntityModel

VERSION

version 0.006

SYNOPSIS

use EntityModel::Log ':all';
# Log everything down to level 0 (debug)
EntityModel::Log->instance->min_level(0);

# STDERR by default, or Test::More::note if you have it loaded
logDebug("Test something");
logInfo("Object [%s] found", $obj->name);
logError("Fatal problem");
logInfo(sub { my $str = heavy_operation(); return 'Failed: %s', $str });

logInfo("Stack trace - note that it must have at least one parameter (%s): %S", 'like this');
logInfo("No stack trace without parameters despite %S");

my $log = EntityModel::Log->instance;
$log->debug("OO-style debug");
$log->info("OO-style info");
$log->warning("OO-style warning");
$log->error("OO-style error");

DESCRIPTION

Yet another logging class. Provides a procedural and OO interface as usual - intended for use with EntityModel only, if you're looking for a general logging framework try one of the other options in the "SEE ALSO" section.

instance

Returns a handle to the main instance of EntityModel::Log.

PROCEDURAL METHODS

_raise_error_on_global_instance

Raise the given (code, message, ...) log event on the EntityModel::Log global instance.

logDebug

Raise a debug message. Expect a high volume of these during normal operation so a production server would typically have these disabled.

logInfo

Raise an informational message, which we'd like to track for stats reasons - indicates normal operations rather than an error condition.

logWarning

Raise a warning message, for things like 'requested delete for object that does not exist'. You might expect a few of these in regular operations due to concurrent access and timing issues, so they may not necessarily indicate real system problems.

logError

Raise an error - this is likely to be a genuine system problem.

logStack

Raise an error with stack - this is likely to be a genuine system problem.

_stack_trace

Get a stack trace, as an array of hashref entries, skipping the top two levels.

_level_from_string

Returns the level matching the given string.

_timestamp

Generate a string in ISO8601-ish format representing the time of this log event.

OO METHODS

new

Constructor - currently doesn't do much.

debug

Display a debug message.

info

Display an info message.

warning

Display a warning message.

error

Display an error message.

path

Accessor for path setting, if given a new path will close existing file and direct all new output to the given path.

pid

Current PID, used for fork tracking.

is_open

Returns true if our log file is already open.

disabled

Returns true if we're running disabled.

close

Close the log file if it's currently open.

close_after_fork

Close any active handle if we've forked. This method just does the closing, not the check for $$.

open

Open the logfile.

reopen

Helper method to close and reopen logfile.

parse_message

Generate appropriate text based on whatever we get passed.

Each item in the parameter list is parsed first, then the resulting items are passed through sprintf. If only a single item is in the list then the resulting string is returned directly.

Item parsing handles the following types:

  • Single string is passed through unchanged

  • Arrayref or hashref is expanded via Data::Dump

  • Other references are stringified

  • Undef items are replaced with the text 'undef'

In addition, if the first parameter is a coderef then it is expanded in place (recursively - a coderef can return another coderef). Note that this only happens for the *first* parameter at each level of recursion.

min_level

Accessor for the current minimum logging level. Values correspond to:

  • 0 - Debug

  • 1 - Info

  • 2 - Warning

  • 3 - Error

  • 4 - Fatal

Returns $self when setting a value, otherwise the current value is returned.

raise

Raise a log message

  • $level - numeric log level

  • @data - message data

output

Sends output to the current filehandle.

get_handle

Returns a handle if we have one, and 0 if we should fall back to Test::More::note.

handle

Direct(-ish) accessor for the file handle.

SEE ALSO

Log::Any, Log::Log4perl or just search for "log" on search.cpan.org, plenty of other options.

AUTHOR

Tom Molesworth <cpan@entitymodel.com>

LICENSE

Copyright Tom Molesworth 2008-2014. Licensed under the same terms as Perl itself.