diff options
| author | David Phillips <david@sighup.nz> | 2017-10-02 00:48:26 +1300 | 
|---|---|---|
| committer | David Phillips <david@sighup.nz> | 2017-10-02 01:09:45 +1300 | 
| commit | 8bc6d6e2f50c2986d2e431af9a994af687f27a40 (patch) | |
| tree | 9b3ea57e7a6ba668b9ab3bcea0fd375fca457923 | |
| parent | ebad7de34ff7ae2cd5cbf883e843942e1190c1f7 (diff) | |
| download | idalius-8bc6d6e2f50c2986d2e431af9a994af687f27a40.tar.xz | |
Change from print to log, add timestamp
| -rwxr-xr-x | idalius.pl | 18 | ||||
| -rw-r--r-- | plugin/tittilate.pm | 2 | ||||
| -rw-r--r-- | plugin/url_title.pm | 6 | 
3 files changed, 16 insertions, 10 deletions
| @@ -2,7 +2,7 @@  use strict;  use warnings; -use POSIX qw(setuid setgid); +use POSIX qw(setuid setgid strftime);  use POE;  use POE::Kernel;  use POE::Component::IRC; @@ -69,6 +69,12 @@ sub drop_priv {  	setuid($config{uid}) or die "Failed to setuid: $!\n";  } +sub log_info { +	# FIXME direct to a log file instead of stdout +	my $stamp = strftime("%Y-%m-%d %H:%M:%S %z", localtime); +	print "$stamp | @_\n"; +} +  sub _start {  	my $heap = $_[HEAP];  	my $irc = $heap->{irc}; @@ -81,7 +87,7 @@ sub irc_001 {  	my $sender = $_[SENDER];  	my $irc = $sender->get_heap(); -	print "Connected to server ", $irc->server_name(), "\n"; +	log_info("Connected to server ", $irc->server_name());  	$irc->yield( join => $_ ) for @{$config{channels}};  	return; @@ -99,7 +105,7 @@ sub irc_nick {  sub irc_kick {  	my ($kicker, $channel, $kickee, $reason) = @_[ARG0 .. ARG3];  	if ($kickee eq $current_nick) { -		print "I was kicked by $kicker ($reason). Rejoining now.\n"; +		log_info("I was kicked by $kicker ($reason). Rejoining now.");  		$irc->yield(join => $channel);  	}  	return; @@ -114,14 +120,14 @@ sub irc_public {  	my $nick = ( split /!/, $who )[0];  	my $channel = $where->[0]; -	print("[$channel] $who: $what\n"); +	log_info("[$channel] $who: $what");  	# reject ignored nicks first  	return if (grep {$_ eq $nick} @{$config{ignore}});  	for my $module (@plugin_list) {  		my $stripped_what = strip_color(strip_formatting($what)); -		my $output = $module->message($irc->nick_name, $who, $where, $what, $stripped_what); +		my $output = $module->message(\&log_info, $irc->nick_name, $who, $where, $what, $stripped_what);  		$irc->yield(privmsg => $where => $output) if $output;  	} @@ -243,6 +249,6 @@ sub _default {  			push ( @output, "'$arg'" );  		}  	} -	print join ' ', @output, "\n"; +	log_info(join ' ', @output);  	return;  } diff --git a/plugin/tittilate.pm b/plugin/tittilate.pm index d9d8a49..51253ec 100644 --- a/plugin/tittilate.pm +++ b/plugin/tittilate.pm @@ -15,7 +15,7 @@ sub configure {  }  sub message { -	my ($self, $me, $who, $where, $raw_what, $what) = @_; +	my ($self, $logger, $me, $who, $where, $raw_what, $what) = @_;  	my $gathered = "";  	my @expressions = (keys %{$config{triggers}});  	my $expression = join '|', @expressions; diff --git a/plugin/url_title.pm b/plugin/url_title.pm index f36ad6d..1c376df 100644 --- a/plugin/url_title.pm +++ b/plugin/url_title.pm @@ -18,7 +18,7 @@ sub configure {  sub message  { -	my ($self, $me, $who, $where, $raw_what, $what) = @_; +	my ($self, $logger, $me, $who, $where, $raw_what, $what) = @_;  	my $url;  	if ($what =~ /(https?:\/\/[^ ]+)/i) { @@ -31,12 +31,12 @@ sub message  	my $response = $http->get($url);  	if (!$response->{success}) { -		print "Something broke: $response->{reason}\n"; +		$logger->("Something broke: $response->{reason}");  		return;  	}  	if (!($response->{headers}->{"content-type"} =~ m,text/html ?,)) { -		print("Not html, giving up now\n"); +		$logger->("Not html, giving up now");  		return;  	} | 
