| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | |||
| 4 | package Bot::Net::Log; | ||
| 5 | |||
| 6 | use FileHandle; | ||
| 7 | use FindBin; | ||
| 8 | use Log::Log4perl; | ||
| 9 | use Readonly; | ||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | Bot::Net::Log - logger for your bot net | ||
| 14 | |||
| 15 | =head1 SYNOPSIS | ||
| 16 | |||
| 17 | Bot::Net->log->debug("Debug message."); | ||
| 18 | Bot::Net->log->info("Info message."); | ||
| 19 | Bot::Net->log->warn("Warning message."); | ||
| 20 | Bot::Net->log->error("Error message."); | ||
| 21 | Bot::Net->log->fatal("Fatal message."); | ||
| 22 | |||
| 23 | =head2 DESCRIPTION | ||
| 24 | |||
| 25 | The provides a logger using the L<Log::Log4perl> facility, which has excellent configuration features. The configuration for your bot net is generally found in F<etc/log4perl.conf>. | ||
| 26 | |||
| 27 | =head1 METHODS | ||
| 28 | |||
| 29 | =head2 new | ||
| 30 | |||
| 31 | Creates the logger. In general, you never need to call this. Use this instead: | ||
| 32 | |||
| 33 | my $log = Bot::Net->log; | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | sub new { | ||
| 38 | my $class = shift; | ||
| 39 | |||
| 40 | # XXX Hack to get tests to work since it depends on the log messages | ||
| 41 | # reported to flush... probably not good for production | ||
| 42 | STDOUT->autoflush(1); | ||
| 43 | STDERR->autoflush(1); | ||
| 44 | |||
| 45 | my $config_file = Bot::Net::Config::_search_for_file('log4perl.conf'); | ||
| 46 | |||
| 47 | Log::Log4perl::init($config_file); | ||
| 48 | bless {}, $class; | ||
| 49 | } | ||
| 50 | |||
| 51 | =head2 get_logger NAME | ||
| 52 | |||
| 53 | Returns the named logger. In general, you never need to call this. Use this instead: | ||
| 54 | |||
| 55 | my $log = Bot::Net->log; | ||
| 56 | |||
| 57 | or: | ||
| 58 | |||
| 59 | my $log = Bot::Net->log('MyBotNet::Bot::CopyBot'); | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | sub get_logger { | ||
| 64 | my $self = shift; | ||
| 65 | my $name = shift; | ||
| 66 | return Log::Log4perl->get_logger($name); | ||
| 67 | } | ||
| 68 | |||
| 69 | =head1 AUTHORS | ||
| 70 | |||
| 71 | Andrew Sterling Hanenkamp C<< <hanenkamp@cpan.org> >> | ||
| 72 | |||
| 73 | =head1 COPYRIGHT AND LICENSE | ||
| 74 | |||
| 75 | Copyright 2007 Boomer Consulting, Inc. All Rights Reserved. | ||
| 76 | |||
| 77 | This program is free software and may be modified and distributed under the same terms as Perl itself. | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | 1; |