You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axkit-dev@xml.apache.org by ma...@sergeant.org on 2006/08/15 00:38:39 UTC

[SVN] [83] A request log (similar to combined log format)

Revision: 83
Author:   matt
Date:     2006-08-14 22:38:21 +0000 (Mon, 14 Aug 2006)

Log Message:
-----------
A request log (similar to combined log format)

Added Paths:
-----------
    trunk/plugins/request_log

Added: trunk/plugins/request_log
===================================================================
--- trunk/plugins/request_log	2006-08-13 16:21:07 UTC (rev 82)
+++ trunk/plugins/request_log	2006-08-14 22:38:21 UTC (rev 83)
@@ -0,0 +1,45 @@
+#!/usr/bin/perl -w
+
+sub init {
+    my $self = shift;
+    
+    $self->register_config('LogFile', sub { $self->logfile(@_) });
+}
+
+sub logfile {
+    my $self = shift;
+    my $conf = shift;
+    
+    my $key = $self->plugin_name . "::log_file";
+    if (@_) {
+        my $value = shift;
+        open(my $fh, ">>$value") || die "open(>> $value) : $!";
+        $conf->notes($key, $fh);
+    }
+    $conf->notes($key);
+}
+
+use POSIX qw(strftime);
+
+sub hook_response_sent {
+    my ($self, $code) = @_;
+    
+    # [07/Aug/2006:21:08:52 +0000]
+    my $time = strftime("[%d/%b/%Y:%H:%M:%S +0000]", gmtime);
+    my $line = sprintf("%s %s %s %s \"%s\" %s %s \"%s\" \"%s\"\n",
+        $self->client->peer_ip_string,
+        '-',
+        '-', # TODO - get username out of headers_in maybe?
+        $time,
+        $self->client->headers_in->request_line,
+        $self->client->headers_out->response_code,
+        '-', # TODO - get bytes sent
+        $self->client->headers_in->header('Referer') || '-',
+        $self->client->headers_in->header('User-Agent') || '-',
+        );
+    
+    my $logfile = $self->logfile($self->config) || die "No LogFile configured";
+    syswrite($logfile, $line) || die "Unable to write to logfile: $!";
+    
+    return DECLINED;
+}