package BaseClass;
sub new {
my $class = shift @_;
my $self = {};
$self = bless $self, $class;
# Re-read the config file if it has changed...
my $mtime = ( stat(CONFIG_FILE) )[9];
if ($mtime != $config_time) {
($config, $config_time) = &_read_config(CONFIG_FILE);
}
return $self;
}
####
package BaseClass::Log;
@ISA = qw( BaseClass );
sub new {
my $class = shift;
my $self = $class->SUPER::new;
my (%opt) = ( @_ );
$self->{opt} = \%opt;
# Connect to the database.
$self->{dbh} = $self->connect_db('hits') || return undef;
return $self;
}
####
package BaseClass::Log::Writer;
@ISA = qw( BaseClass::Log );
sub new {
my $class = shift @_;
my $self = $class->SUPER::new;
my (%opt) = (@_);
# Standard fields for the Log module go in this array.
@self::_properties = qw( type_id
class_id
subclass_id
severity
process_id
text_info
program_name
module_name
unix_pid
host_name
purge_date
);
# We can set up some defaults for process and such.
$opt{unix_pid} = $$ unless $opt{unix_pid};
$opt{program_name} = $0 unless $opt{program_name};
$opt{hostname} = $ENV{HOSTNAME} unless $opt{hostname};
$opt{module_name} = caller || $opt{program_name}
unless $opt{module_name};
$opt{purge_date} = POSIX::strftime("%Y-%m-%d", localtime(time))
unless $opt{purge_date};
$opt{type_id} = 'unknown' unless $opt{type_id};
$opt{class_id} = 'unknown' unless $opt{class_id};
$opt{subclass_id} = 'unknown' unless $opt{subclass_id};
$opt{severity} = 0 unless $opt{severity};
$self->{opt} = \%opt;
return $self;
}