3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-07 04:29:32 +01:00
pbot/PBot/Logger.pm
Pragmatic Software d955bfa06c Add centralized configuration registry module
Allows changing of bot configuration values without needing to restart
bot instance or needing to edit pbot.pl script.

Registry will initially be populated with default values from pbot.pl,
but if a registry file exists then the registry values will take
precedence over the pbot.pl values. For instance, if you regset the
bot trigger to '%' then the trigger will be '%' even if pbot.pl has '!'
or something else explicitly set.

Some registry items can have trigger hooks associated with them.  For
instance, the irc->botnick registry entry has a change_botnick_trigger
associated with it which changes the IRC nick on the server when a new
value is set via regset/regadd.

Tons of other fixes and improvements throughout.
2014-05-17 20:08:19 +00:00

43 lines
686 B
Perl

package PBot::Logger;
use warnings;
use strict;
use Carp ();
sub new {
if(ref($_[1]) eq 'HASH') {
Carp::croak("Options to Logger should be key/value pairs, not hash reference");
}
my ($class, %conf) = @_;
my $log_file = delete $conf{log_file};
if(defined $log_file) {
open PLOG_FILE, ">>$log_file" or Carp::croak "Couldn't open log file: $!\n" if defined $log_file;
PLOG_FILE->autoflush(1);
}
my $self = {
log_file => $log_file,
};
bless $self, $class;
return $self;
}
sub log {
my ($self, $text) = @_;
my $time = localtime;
if(defined $self->{log_file}) {
print PLOG_FILE "$time :: $text";
}
print "$time :: $text";
}
1;