root/Log-Dispatch-DBI/trunk/README

Revision 353 (checked in by miyagawa, 19 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 NAME
2     Log::Dispatch::DBI - Class for logging to database via DBI interface
3
4 SYNOPSIS
5       use Log::Dispatch::DBI;
6
7       my $log = Log::Dispatch::DBI->new(
8           name       => 'dbi',
9           min_level  => 'info',
10           datasource => 'dbi:mysql:log',
11           username   => 'user',
12           password   => 'password',
13           table      => 'logging',
14       );
15
16       # Or, if your handle is alreaady connected
17       $log = Log::Dispatch::DBI->new(
18           name => 'dbi',
19           min_level => 'info',
20           dbh  => $dbh,
21       );
22
23       $log->log(level => 'emergency', messsage => 'something BAD happened');
24
25 DESCRIPTION
26     Log::Dispatch::DBI is a subclass of Log::Dispatch::Output, which inserts
27     logging output into relational database using DBI interface.
28
29 METHODS
30     new $log = Log::Dispatch::DBI->new(%params);
31
32         This method takes a hash of parameters. The following options are
33         valid:
34
35     -- name, min_level, max_level, callbacks
36         Same as various Log::Dispatch::* classes.
37
38     -- dbh
39         Database handle where Log::Dispatch::DBI throws log message.
40
41     -- datasource, username, password
42         If database connection is not yet established, put the DSN, username
43         and password for DBI connect method. Destructor method of
44         Log::Dispatch::DBI disconnects database handle, if the handle is
45         made inside by these parameters. (The method does not disconnect the
46         handle if it's supplied with `dbh' parameter.)
47
48     -- table
49         Table name for logging. default is log.
50
51     log_message
52         inherited from Log::Dispatch::Output.
53
54 TABLE SCHEMA
55     Maybe something like this for MySQL.
56
57       CREATE TABLE log (
58           id        int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
59           level     varchar(9) NOT NULL,
60           message   text NOT NULL,
61           timestamp timestamp
62       );
63
64     For example,
65
66       $log->log(level => 'info', message => 'too bad');
67
68     will execute the following SQL:
69
70       INSERT INTO log (level, message) VALUES ('info', 'too bad');
71
72     If you change this behaviour, what you should do is to subclass
73     Log::Dispatch::DBI and override `create_statement' and `log_message'
74     method.
75
76 AUTHOR
77     Tatsuhiko Miyagawa <miyagawa@bulknews.net>
78
79     This library is free software; you can redistribute it and/or modify it
80     under the same terms as Perl itself.
81
82 SEE ALSO
83     the Log::Dispatch manpage, the DBI manpage, the Log::Dispatch::Config
84     manpage
85
Note: See TracBrowser for help on using the browser.