--- trunk/bin/irc-logger.pl 2008/02/07 17:48:51 77
+++ trunk/bin/irc-logger.pl 2008/03/06 18:03:05 84
@@ -22,6 +22,10 @@
Name of log file
+=item --follow=file.log
+
+Follows new messages in file
+
=back
=head1 DESCRIPTION
@@ -46,11 +50,8 @@
$CHANNEL = '#irc-logger' if ($HOSTNAME =~ m/llin/);
my $IRC_ALIAS = "log";
-my %FOLLOWS =
- (
- ACCESS => "/var/log/apache/access.log",
- ERROR => "/var/log/apache/error.log",
- );
+# default log to follow and announce messages
+my $follows_path = 'follows.log';
my $DSN = 'DBI:Pg:dbname=' . $NICK;
@@ -59,6 +60,9 @@
my $sleep_on_error = 5;
+# number of last tags to keep in circular buffer
+my $last_x_tags = 50;
+
my $http_port = $NICK =~ m/-dev/ ? 8001 : 8000;
my $url = "http://$HOSTNAME:$http_port";
@@ -93,6 +97,7 @@
my $log_path;
GetOptions(
'import-dircproxy:s' => \$import_dircproxy,
+ 'follows:s' => \$follows_path,
'log:s' => \$log_path,
);
@@ -106,6 +111,24 @@
print strftime($TIMESTAMP,localtime()), ' ', join(" ",@_), $/;
}
+# LOG following
+
+my %FOLLOWS =
+ (
+# ACCESS => "/var/log/apache/access.log",
+# ERROR => "/var/log/apache/error.log",
+ );
+
+sub add_follow_path {
+ my $path = shift;
+ my $name = $path;
+ $name =~ s/\..*$//;
+ warn "# using $path to announce messages from $name\n";
+ $FOLLOWS{$name} = $path;
+}
+
+add_follow_path( $follows_path ) if ( -e $follows_path );
+
# HTML formatters
my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"');
@@ -483,7 +506,6 @@
=cut
-my $last_x_tags = 5;
my @last_tags;
sub add_tag {
@@ -622,7 +644,7 @@
$_[KERNEL]->post($IRC_ALIAS => join => $CHANNEL);
$_[KERNEL]->post($IRC_ALIAS => join => '#logger');
$_[KERNEL]->yield("heartbeat"); # start heartbeat
-# $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS;
+ $_[KERNEL]->yield("my_add", $_) for keys %FOLLOWS;
$_[KERNEL]->post( $IRC_ALIAS => privmsg => 'nickserv', "IDENTIFY $NICK" );
},
irc_public => sub {
@@ -653,7 +675,7 @@
},
irc_ping => sub {
- warn "pong ", $_[ARG0], $/;
+ _log( "pong ", $_[ARG0] );
$ping->{ $_[ARG0] }++;
},
irc_invite => sub {
@@ -859,10 +881,11 @@
Filename => $FOLLOWS{$trailing},
InputEvent => 'got_line',
);
+ warn "+++ following $trailing at $FOLLOWS{$trailing}\n";
},
got_line => sub {
- $_[KERNEL]->post($session => my_tailed =>
- time, $trailing, $_[ARG0]);
+ warn "+++ $trailing : $_[ARG0]\n";
+ $_[KERNEL]->post($session => my_tailed => time, $trailing, $_[ARG0]);
},
},
);
@@ -914,6 +937,11 @@
my $httpd = POE::Component::Server::HTTP->new(
Port => $http_port,
+ PreHandler => {
+ '/' => sub {
+ $_[0]->header(Connection => 'close')
+ }
+ },
ContentHandler => { '/' => \&root_handler },
Headers => { Server => 'irc-logger' },
);
@@ -959,6 +987,9 @@
my ($request, $response) = @_;
$response->code(RC_OK);
+ # this doesn't seem to work, so moved to PreHandler
+ #$response->header(Connection => 'close');
+
return RC_OK if $request->uri =~ m/favicon.ico$/;
my $q;
@@ -973,9 +1004,9 @@
my $search = $q->param('search') || $q->param('grep') || '';
- if ($request->url =~ m#/rss(?:/(tags)(?:=(\d+))?)#i) {
+ if ($request->url =~ m#/rss(?:/(tags|last-tag)\w*(?:=(\d+))?)?#i) {
my $show = lc($1);
- my $arg = $2 || 50;
+ my $nr = $2;
my $type = 'RSS'; # Atom
@@ -987,11 +1018,12 @@
my $feed = XML::Feed->new( $type );
if ( $show eq 'tags' ) {
+ $nr ||= 50;
$feed->title( "tags from $CHANNEL" );
$feed->link( "$url/tags" );
$feed->description( "tag cloud created from messages on channel $CHANNEL which have tags// in them" );
my $feed_entry = XML::Feed::Entry->new($type);
- $feed_entry->title( "$arg tags from $CHANNEL" );
+ $feed_entry->title( "$nr tags from $CHANNEL" );
$feed_entry->author( $NICK );
$feed_entry->link( '/#tags' );
@@ -999,14 +1031,17 @@
qq{}
. $cloud->css
. qq{}
- . $cloud->html( $arg )
+ . $cloud->html( $nr )
. qq{]]>}
);
$feed->add_entry( $feed_entry );
- } else {
+ } elsif ( $show eq 'last-tag' ) {
- $feed->title( "last $last_x_tags from $CHANNEL" );
+ $nr ||= $last_x_tags;
+ $nr = $last_x_tags if $nr > $last_x_tags;
+
+ $feed->title( "last $nr tagged messages from $CHANNEL" );
$feed->link( $url );
$feed->description( "collects messages which have tags// in them" );
@@ -1021,7 +1056,7 @@
my $message = $filter->{message}->( $m->{message} );
$message .= "
\n" unless $message =~ m!<(/p|br/?)>!;
- warn "## message = $message\n";
+# warn "## message = $message\n";
from_to( $message, $ENCODING, 'UTF-8' );
#$feed_entry->summary(
@@ -1030,7 +1065,15 @@
);
$feed_entry->category( join(', ', @{$m->{tags}}) );
$feed->add_entry( $feed_entry );
+
+ $nr--;
+ last if $nr <= 0;
+
}
+
+ } else {
+ warn "!! unknown rss request for $show\n";
+ return RC_DENY;
}
$response->content( $feed->as_xml );
@@ -1090,9 +1133,9 @@
$cal->weekdays('MON','TUE','WED','THU','FRI');
($l_yyyy,$l_mm) = ($yyyy,$mm);
}
- $cal->setcontent($dd, qq{
+ $cal->setcontent($dd, qq[
$row->{nr}
$row->{len}
- });
+ ]);
}
$html .= qq{