Skip to content

Instantly share code, notes, and snippets.

@anazawa
Created May 24, 2012 01:11
Show Gist options
  • Select an option

  • Save anazawa/2778763 to your computer and use it in GitHub Desktop.

Select an option

Save anazawa/2778763 to your computer and use it in GitHub Desktop.
Apache 風のアクセス・ログを出力する Blosxom plugin
package access_log;
use strict;
use warnings;
use POSIX qw/strftime/;
sub start { !$blosxom::static_entries }
sub last {
my $h = $ENV{REMOTE_ADDR};
my $l = '-';
my $u = '-';
my $t = strftime( "[%d/%b/%Y:%H:%M:%S %z]", localtime );
my $r = join ' ', @ENV{qw/REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL/};
my $b = length $blosxom::output;
my $status = $blosxom::header->{-status};
my $s = $status ? ( split / /, $status )[0] : '200';
my $referer = $ENV{HTTP_REFERER} || q{};
my $user_agent = $ENV{HTTP_USER_AGENT};
if ( open my $fh, '>>', "$blosxom::plugin_state_dir/access_log" ) {
print $fh qq{$h $l $u $t "$r" $s $b "$referer" "$user_agent"\n};
close $fh;
}
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment