package Apache::MyLog; use strict; use Apache (); use DBI (); use Apache::Constants qw(:common); use POSIX; $Apache::MyLog::VERSION = '0.01'; sub handler { my $r = shift; return DECLINED unless ($r->is_main); my %Config = ('dsn' => $r->dir_config('MyLog_dsn'), 'user' => $r->dir_config('MyLog_user'), 'pwd' => $r->dir_config('MyLog_pwd'), 'table' => $r->dir_config('MyLog_table') ); if (!$Config{dsn} || !$Config{user} || !$Config{pwd} || !$Config{table}) { $r->log_error("MyLog.pm not properly configured."); return DECLINED; } my $dbh = DBI->connect($Config{dsn}, $Config{user}, $Config{pwd}); if (!$dbh) { $r->log_reason("Connection to database failed.", $r->uri); return DECLINED; } my @INFO = ($r->get_remote_host, $r->connection->user, strftime("%Y-%m-%d %I:%M:%S", localtime), $r->uri, $r->status, $r->bytes_sent, $r->method, $r->header_in('Referer'), $r->header_in('User-Agent') ); my $query = "insert into $Config{table} (remote_host, user, time_stamp, requested, status, bytes, method, referer, browser) values (" . (join(",",("?") x @INFO)) . ")"; my $sth; unless ($sth = $dbh->prepare($query)) { $r->log_reason("Can not prepare statement: $DBI::errstr", $r->uri); $dbh->dicsonnect; return DECLINED; } $sth->execute(@INFO); $dbh->disconnect; return OK; } 1; __END__