NAME
Log::Handler::Plugin::DBI::CreateTable - A helper for Log::Hander::Output::DBI to create your 'log' table
Synopsis
See scripts/create.table.pl and scripts/drop.table.pl.
The programs use these methods: "create_log_table()" and "drop_log_table()".
Description
This module is a customised wrapper for DBIx::Admin::CreateTable, which means it handles a range of database server SQL formats for creating tables and the corresponding sequences.
Likewise for dropping tables and sequences.
The table name defaults to 'log', and it has the correct structure to be compatible with Log::Handler::Output::DBI.
Distributions
This module is available as a Unix-style distro (*.tgz).
See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing distros.
Installation
Install Log::Handler::Plugin::DBI as you would for any Perl
module:
Run:
cpanm Log::Handler::Plugin::DBI
or run:
sudo cpan Log::Handler::Plugin::DBI
or unpack the distro, and then either:
perl Build.PL
./Build
./Build test
sudo ./Build install
or:
perl Makefile.PL
make (or dmake or nmake)
make test
make install
Constructor and Initialization
new()
is called as my($app) = Log::Handler::Plugin::DBI::CreateTable -> new(k1 => v1, k2 => v2, ...)
.
It returns a new object of type Log::Handler::Plugin::DBI::CreateTable
.
Key-value pairs accepted in the parameter list (see corresponding methods for details [e.g. "config([$hashref])"]):
- o config => $hashref
-
The keys and values of this hashref are documented below under "config([$hashref])".
Methods
config([$hashref])
Gets or sets the hashref of options used by the other methods.
Here, the [] indicate an optional parameter.
The hashref takes these (key => value) pairs:
- o dsn => $string
-
A typical $string might be 'dbi:SQLite:dbname=/tmp/logger.test.sqlite'.
- o username => $string
-
Supply your database server username, or leave empty for databases such as SQLite.
- o password => $string
-
Supply your database server password, or leave empty for databases such as SQLite.
- o table_name => $string
-
Supply your log table name, or let it default to 'log'.
'config' is a parameter to "new()". See "Constructor and Initialization" for details.
create_log_table()
Creates the table named in the config hashref passed in to new.
drop_log_table()
Drops the table named in the config hashref passed in to new.
FAQ
When would I use this module?
You use scripts/*.pl in preparation for using any class or program which you want to log to a database.
Having create the 'log' table, then you write code using Log::Handler::Plugin::DBI.
For sample code, study CGI::Snapp::Demo::Four.
What is the expected structure of the 'log' table?
In pseudo-code:
id primary key + (db_vendor-dependent stuff)
level varchar(255) not null,
message not null + (db_vendor eq 'ORACLE' ? 'long' : 'text')
timestamp timestamp not null default current_timestamp +
(db_vendor =~ /(?:MySQL|Postgres)/i ? '(0) without time zone' : '')
Also, if you are using MySQL, you might want to set the engine=innodb option.
See scripts/create.table.pl and scripts/drop.table.pl for an easy way to do all this.
Can this module be used in any module?
Sure, but it is not a plugin like Log::Handler::Plugin::DBI is.
See Also
Config::Plugin::Tiny - A plugin which uses Config::Tiny
Config::Plugin::TinyManifold - A plugin which uses Config::Tiny with 1 of N sections
Log::Handler::Plugin::DBI - A plugin for Log::Handler using Log::Hander::Output::DBI
Log::Handler::Plugin::DBI::CreateTable - A helper for Log::Hander::Output::DBI to create your 'log' table
Machine-Readable Change Log
The file CHANGES was converted into Changelog.ini by Module::Metadata::Changes.
Version Numbers
Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
Support
Email the author, or log a bug on RT:
https://rt.cpan.org/Public/Dist/Display.html?Name=Log::Handler::Plugin::DBI.
Author
Log::Handler::Plugin::DBI::CreateTable was written by Ron Savage <ron@savage.net.au> in 2012.
Home page: http://savage.net.au/index.html.
Copyright
Australian copyright (c) 2012, Ron Savage.
All Programs of mine are 'OSI Certified Open Source Software';
you can redistribute them and/or modify them under the terms of
The Artistic License, a copy of which is available at:
http://www.opensource.org/licenses/index.html