Leyland::Manual::Logging - How to use a log in Leyland applications
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, Log::Log4perl and many others (not to mention plain old print STDOUT/STDERR $log_msg).
print STDOUT/STDERR $log_msg
Before v1.0.0, Leyland had its own logging mechanism. Since v1.0.0, however, Leyland refers to Plack middlewares for the purpose of logging, but still provides a default logger that simply prints to standard output.
Selecting a logging middleware is done as you would in any Plack application. For example, to use Plack::Middleware::LogDispatch, do this in your app's PSGI file:
# in app.psgi use MyLeylandApp; use Log::Dispath; builder { enable "LogDispatch", logger => Log::Dispatch->new(...); MyLeylandApp->new->to_app; };
Refer to the documentation of your preferred logging middleware for complete instructions.
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. Leyland supports the following log levels:
trace
debug
info (with an inform alias)
notice
warning (with a warn alias)
error (with an err alias)
critical (with a crit and fatal aliases)
fatal
alert
emergency
Printing to the log is done from the context object using its log attribute. For example:
log
get '^/$' { $c->log->info("Got a request to display the index page"); $c->template('index.html'); }
And that's pretty much it.
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-2014 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.