Mercurial > repos > stheil > taxonomy_sqlite
comparison perl/lib/Logger/Logger.pm @ 0:4ecb2ce50254 draft default tip
Uploaded
author | stheil |
---|---|
date | Mon, 26 Oct 2015 10:59:07 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4ecb2ce50254 |
---|---|
1 #!/usr/bin/perl | |
2 # $Id: Logger.pm,v 1.3 2011/07/01 18:07:31 nguilhot Exp $ | |
3 package Logger::Logger; | |
4 | |
5 ################################################## | |
6 ## Included modules | |
7 ################################################## | |
8 ## Perl modules | |
9 use strict; | |
10 use warnings; | |
11 use diagnostics; | |
12 use Log::Log4perl; | |
13 use Log::Log4perl::Layout; | |
14 use Log::Log4perl::Level; | |
15 use Exporter 'import'; | |
16 | |
17 our $logger; | |
18 our @EXPORT = qw($logger); | |
19 | |
20 $logger = Log::Log4perl->get_logger(''); | |
21 | |
22 # Define stdout Appender, by default messages will only be logged to stdout | |
23 # In order to log messages to a file, you need to call the initFileLoggers | |
24 # method with the name of folder where to create the log files | |
25 my $stdout_layout = Log::Log4perl::Layout::PatternLayout->new("%5p - %m%n"); | |
26 my $stdout_appender = Log::Log4perl::Appender->new( | |
27 "Log::Log4perl::Appender::Screen", | |
28 name => 'screenlog', | |
29 stderr => 1); | |
30 $stdout_appender->layout($stdout_layout); | |
31 $stdout_appender->threshold($INFO); | |
32 $logger->add_appender($stdout_appender); | |
33 $logger->level($INFO); | |
34 | |
35 | |
36 | |
37 sub changeMode { | |
38 my ($s,$verbosity) = @_; | |
39 my $debug_layout = Log::Log4perl::Layout::PatternLayout->new("%d %5p> %F{1}:%L %M - %m%n"); | |
40 my $debug_appender = Log::Log4perl::Appender->new( | |
41 "Log::Log4perl::Appender::Screen", | |
42 name => 'debuglog', | |
43 stderr => 0); | |
44 $debug_appender->layout($debug_layout); | |
45 $logger->add_appender($debug_appender); | |
46 $logger->remove_appender('screenlog'); | |
47 | |
48 if($verbosity == 3){ | |
49 $stdout_appender->threshold($DEBUG); | |
50 $logger->level($DEBUG); | |
51 } | |
52 if($verbosity == 4){ | |
53 | |
54 $stdout_appender->threshold($TRACE); | |
55 $logger->level($TRACE); | |
56 } | |
57 } | |
58 | |
59 1; |