Súbor: [Platon] / perl-modules / Platon / Log.pm (stiahnutie)
Revízia 1.5, Sun Dec 4 21:34:24 2005 UTC (19 years, 5 months ago) by rajo
Zmeny od 1.4: +3 -2
[lines]
Implemented "cache" feature. Speed improvements 39%.
|
#
# Platon::Log.pm - save logfiles into database
#
# Developed by Lubomir Host 'rajo' <rajo AT platon.sk>
# Copyright (c) 2004 Platon SDG, http://platon.sk/
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# Changelog:
# 2004-10-15 - created
#
# $Platon: perl-modules/Platon/Log.pm,v 1.4 2005/03/15 23:20:10 rajo Exp $
package Platon::Log;
use strict;
use Carp;
use AppConfig qw/:expand :argcount/;
use Platon::DBI;
use vars qw($VERSION $DEBUG);
use base qw( Platon );
$VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
sub new
{ #{{{
my $this = shift;
my $conf = shift;
my $class = ref($this) || $this;
my $self = { };
unless (defined $conf) {
$conf = AppConfig->new(
{
CASE => 1,
DEBUG => 0,
CREATE => 0,
GLOBAL => {
ARGCOUNT => ARGCOUNT_NONE,
DEFAULT => 0,
}
},
'config|cfg=s', { DEFAULT => "/etc/syslog-ng/mysql.conf" },
'verbose!', { DEFAULT => 0 },
"version", {
ACTION => sub { print "$0 version $VERSION"; exit 0 }
},
'data_source=s', { DEFAULT => 'mysql' },
'host=s', { DEFAULT => 'localhost' },
'database=s', { DEFAULT => 'test' },
'table=s', { DEFAULT => 'log_mail_postfix' },
'user=s', { DEFAULT => 'testuser' },
'password=s', { DEFAULT => 'TestPassword' },
'mysql_connect_timeout', { DEFAULT => 10 },
'mysql_compression', { DEFAULT => 0 },
'cache', { DEFAULT => 1 },
) or die "Can't initialize the AppConfig object\n";
$conf->file($conf->cfg) if -r $conf->cfg; # read the config file
$conf->getopt; # parse command line
$conf->file($conf->cfg) if -r $conf->cfg; # read the config file
}
$self->{conf} = $conf;
unless (defined ($self->{dbh})) {
$self->{dbh} = Platon::DBI->connect(
"DBI:" . $conf->data_source .
":database=" . $conf->database .
";host=" . $conf->host .
";mysql_connect_timeout=" . $conf->mysql_connect_timeout .
";mysql_compression=" . $conf->mysql_compression,
$conf->user, $conf->password) or die Platon::DBI->errstr;
}
bless $self, $class;
$self->_init($conf);
return $self;
} # }}}
sub savelog($$;)
{ # {{{
my ($self, $line) = @_;
print STDERR "# This is default method";
print STDERR "# Please, use \'use Platon::Log::ServiceType::YourService\' instead";
print $line;
return 0;
} # }}}
# store prepared SQL statement into object $self
sub prepare_keyword($$;)
{ # {{{
my ($self, $keyword, $sql_query) = @_;
my ($caller_pkg, $caller_file, $caller_line) = caller;
$self->{$keyword} = $self->{dbh}->prepare($keyword, $sql_query, $caller_pkg, $caller_file, $caller_line);
} # }}}
# this method must be defined in your own Platon::Log::ServiceType::YourService module
sub _init($$;)
{ # {{{
my ($self, $conf) = @_;
print STDERR "# This is default method";
print STDERR "# Please, please, define method _init() in you $self module";
} # }}}
1;
__END__
=head1 NAME
Log - <<<description of module>>>
=head1 SYNOPSIS
use Log;
my $xxx = new Log;
=head1 DESCRIPTION
The Log module allows you ...
<<<your description here>>>
=head2 EXPORT
<<here describe exported methods>>>
=head1 SEE ALSO
=head1 AUTHORS
Lubomir Host 'rajo', <rajo AT platon.sk>
=cut
# vim: ts=4
# vim600: fdm=marker fdl=0 fdc=3
Platon Group <platon@platon.sk> http://platon.sk/
|