View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Nikolay Aviltsev > Dancer-Plugin-Log-DB-0.01 > Dancer::Plugin::Log::DB



Annotate this POD

View/Report Bugs
Module Version: 0.01   Source   Latest Release: Dancer-Plugin-Log-DB-0.04


Dancer::Plugin::Log::DB - log arbitrary messages into a database from within your Dancer application.


Version 0.01


        use Dancer;
        use Dancer::Plugin::Log::DB;

        get '/' => sub {
                # Simple usage - timestamp is NOW 
                log_db { message => 'Simple log message' };

                # Both message and timestamp are set
                log_db { message => 'Message at certain time', timestamp => 9982481 };

                # Using additional fields for complementary information
                log_db { message => 'Another simple message', server_id => $my_server_id }; 

Database connection details and plugin settings are read from application config file - see below on more details.


Provides an easy way to add arbitrary logging messages into a database for your Dancer application. Supports more than one common field ('message') to add bits of information into.

You can add as many fields as you wish in your database table and fill them in with log_db calls.

Default fields are message and timestamp, thus at its simplest case it requires database table with the following SQL declaration:

You can expand functionality by adding any number of columns and write any data supported by your database backend.

For example, in complement to existing timestamp and message fields you can also add server_id column to store server id which left the message.


Table to keep logs should be called 'logs' in your database. This is not configurable in this version. I'm really sorry.

This plugin makes use of great Dancer::Plugin::Database plugin, thus configuration is divided into 2 parts - database configuration and plugin configuration:

                                driver: 'mysql'
                                database: 'test'
                                host: 'localhost'
                                port: 3306
                                username: 'logs_username'
                                password: 'logs_password'
                                message_field_name: 'message'
                                timestamp_field_name: 'timestamp'
                                        - 'server_id'
                                        - 'author_id'

In the simplest case log section can be empty. In this case message field name should be message, timestamp field name should be timestamp.

If you want to rename message and timestamp to something more clear in your database logs table, make sure you set corresponding names in message_field_name and timestamp_field_name under the log section.

If you try to leave a log message in a field which is not listed within additional_fields, you will get an exception.


Table name in your database backend should be called 'logs' and it's not configurable at the moment. I'm terribly sorry for this inconvenience and I promise I will fix this in the 0.02 version.


This is the 0.01 version and there are bugs. Your feedbacks are greatly welcome.


Add configuration parameter to set logs table name in database backend.

Add more tests for various database engines.


Thanks to David Precious for the Dancer::Plugin::Database plugin.

Thanks to my wife for support.


Nikolay Aviltsev,


Copyright 2012 Nikolay Aviltsev.

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 for more information.




syntax highlighting: