Leyland::Manual::Logging - How to use a log in Leyland applications
version 0.001007
Logging is an important aspect of any web application, at least in my opinion. There are quite a lot of options on CPAN for logging, such as Log::Dispatch, Log::Handler (my favorite), Log::Log4perl and many others (not to mention plain old print STDERR $log_msg).
print STDERR $log_msg
Leyland gives you the ability to choose which logging platform to use. Currently, Log::Dispatch and Log::Handler are supported, plus a default platform that simply logs to the standard error output.
You tell Leyland which platform to use with the "logger" option in your application's $config variable (see "CONFIGURING LEYLAND APPLICATIONS" in Leyland::Manual::Applications for more info). The "logger" option is expected to be a hash-ref with two keys: "class", which defines the log class to use, and "opts", which is a hash-ref of options that are specific to the log class chosen.
$config
The three current log classes are LogDispatch, LogHandler and STDERR (the latter takes no arguments and is the default, so there's no need to define it if you want to use it). Refer to the documentation of the log class of your choice to learn about how to configure it. Here's a Log::Dispatch example:
# in app.psgi my $config = { ... logger => { class => 'LogDispatch', opts => { outputs => [ [ 'File', min_level => 'debug', filename => "myapp.$ENV{PLACK_ENV}.log", newline => 1 ], [ 'Screen', min_level => 'warning', newline => 1 ], ], } }, ... };
As you can see, we are telling leyland that our log class is going to be Leyland::Logger::LogDispatch, and that we want our log messages to be printed to the screen, and also to a file.
As you may already know, when using logging platforms, every log message you print is assigned a log level, which denotes the severity of the message. Common levels are "info", "warn" and "error". Unfortunately, different log classes have different log levels, so Leyland only supports levels which are common to all classes. These are "info", "warn", "error" and "debug".
Once initialized, a log object will be available both to your application object and also to every context object:
get '^/$' { $c->log->info("Got a request to display the index page"); $c->template('index.html'); }
And that's pretty much it.
See "WHY AREN'T YOU USING PLACK'S LOGGING MIDDLEWARES?" in Leyland::Manual::FAQ for the answer.
Read Leyland::Manual::Exceptions to learn how to return proper HTTP exceptions or return to the table of contents.
Ido Perlmuter, <ido at ido50.net>
<ido at ido50.net>
Please report any bugs or feature requests to bug-Leyland at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Leyland. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-Leyland at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Leyland::Manual::Views
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Leyland
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Leyland
CPAN Ratings
http://cpanratings.perl.org/d/Leyland
Search CPAN
http://search.cpan.org/dist/Leyland/
Copyright 2010-2011 Ido Perlmuter.
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.
To install Leyland, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Leyland
CPAN shell
perl -MCPAN -e shell install Leyland
For more information on module installation, please visit the detailed CPAN module installation guide.