EntityModel::Log - simple logging support for EntityModel
version 0.006
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");
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.
Returns a handle to the main instance of EntityModel::Log.
Raise the given (code, message, ...) log event on the EntityModel::Log global instance.
Raise a debug message. Expect a high volume of these during normal operation so a production server would typically have these disabled.
Raise an informational message, which we'd like to track for stats reasons - indicates normal operations rather than an error condition.
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.
Raise an error - this is likely to be a genuine system problem.
Raise an error with stack - this is likely to be a genuine system problem.
Get a stack trace, as an array of hashref entries, skipping the top two levels.
Returns the level matching the given string.
Generate a string in ISO8601-ish format representing the time of this log event.
Constructor - currently doesn't do much.
Display a debug message.
Display an info message.
Display a warning message.
Display an error message.
Accessor for path setting, if given a new path will close existing file and direct all new output to the given path.
Current PID, used for fork tracking.
Returns true if our log file is already open.
Returns true if we're running disabled.
Close the log file if it's currently open.
Close any active handle if we've forked. This method just does the closing, not the check for $$.
Open the logfile.
Helper method to close and reopen logfile.
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.
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 a log message
$level - numeric log level
@data - message data
Sends output to the current filehandle.
Returns a handle if we have one, and 0 if we should fall back to Test::More::note.
Direct(-ish) accessor for the file handle.
Log::Any, Log::Log4perl or just search for "log" on search.cpan.org, plenty of other options.
Tom Molesworth <cpan@entitymodel.com>
Copyright Tom Molesworth 2008-2014. Licensed under the same terms as Perl itself.
To install EntityModel::Log, copy and paste the appropriate command in to your terminal.
cpanm
cpanm EntityModel::Log
CPAN shell
perl -MCPAN -e shell install EntityModel::Log
For more information on module installation, please visit the detailed CPAN module installation guide.