brmd::Log: New POE component, logging notify_door_* using Logger::Syslog

This commit is contained in:
Petr Baudis 2011-10-19 00:32:45 +02:00
parent f926e5b869
commit 61323b1dfb

View file

@ -18,6 +18,7 @@ my $irc = brmd::IRC->new();
my $web = brmd::WWW->new();
my $door = brmd::Door->new();
my $stream = brmd::Stream->new();
my $log = brmd::Log->new();
my $alphasign = brmd::Alphasign->new();
@ -27,7 +28,7 @@ POE::Session->create(
status_update streaming_update
notify_door_unlocked notify_door_unauth) ],
],
heap => { irc => $irc, web => $web, door => $door, stream => $stream, alphasign => $alphasign },
heap => { irc => $irc, web => $web, door => $door, stream => $stream, log => $log, alphasign => $alphasign },
);
$poe_kernel->run();
@ -90,12 +91,14 @@ sub notify_door_unlocked {
my ($self, $nick) = @_[OBJECT, ARG0];
$poe_kernel->post($irc, 'notify_door_unlocked', $nick);
$poe_kernel->post($log, 'notify_door_unlocked', $nick);
}
sub notify_door_unauth {
my ($self, $cardid) = @_[OBJECT, ARG0];
$poe_kernel->post($irc, 'notify_door_unauth');
$poe_kernel->post($log, 'notify_door_unauth', $cardid);
}
@ -716,6 +719,60 @@ sub stream_stop {
1;
## Logging
package brmd::Log;
use POE;
use Logger::Syslog;
sub new {
my $class = shift;
my $self = bless { }, $class;
POE::Session->create(
object_states => [
$self => [ qw(_start _default
notify_door_unauth notify_door_unlocked) ],
],
);
return $self;
}
sub _start {
$_[KERNEL]->alias_set("$_[OBJECT]");
$poe_kernel->post($door, 'register');
}
sub _default {
my ($event, $args) = @_[ARG0 .. $#_];
my @output = ( (scalar localtime), "Log $event: " );
for my $arg (@$args) {
if ( ref $arg eq 'ARRAY' ) {
push( @output, '[' . join(', ', @$arg ) . ']' );
}
else {
push( @output, "'$arg'" );
}
}
print join ' ', @output, "\n";
}
sub notify_door_unauth {
my ($sender, $cardid) = @_[SENDER, ARG0];
error ("[door] unauthorized access denied for card " . $cardid);
}
sub notify_door_unlocked {
my ($sender, $nick) = @_[SENDER, ARG0];
info ("[door] unlocked by " . $nick);
}
1;
## Alphasign LED Display
package brmd::Alphasign;