The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Leyland::Manual::Logging - How to use a log in Leyland applications

LOGGING

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).

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

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.

PRINTING LOG MESSAGES

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)

  • alert

  • emergency

Printing to the log is done from the context object using its log attribute. For example:

        get '^/$' {
                $c->log->info("Got a request to display the index page");
                $c->template('index.html');
        }

And that's pretty much it.

WHAT'S NEXT?

Read Leyland::Manual::Exceptions to learn how to return proper HTTP exceptions or return to the table of contents.

AUTHOR

Ido Perlmuter, <ido at ido50.net>

BUGS

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.

SUPPORT

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

        perldoc Leyland::Manual::Views

You can also look for information at:

LICENSE AND COPYRIGHT

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.