diff options
author | Florian Pritz <bluewind@xinu.at> | 2017-04-02 11:16:13 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2017-04-02 11:16:13 +0200 |
commit | 9310b39e245f94e09df2bb99a686c54e54203a9f (patch) | |
tree | 57b4b0d120ace899bd7ad0b453c14a41c126a796 /script | |
parent | 4b3c6874da1c45a666b58582f93254cfd5150d7d (diff) | |
download | App-BorgRestore-9310b39e245f94e09df2bb99a686c54e54203a9f.tar.gz App-BorgRestore-9310b39e245f94e09df2bb99a686c54e54203a9f.tar.xz |
Use Log4perl for logging
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'script')
-rwxr-xr-x | script/borg-restore.pl | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/script/borg-restore.pl b/script/borg-restore.pl index 7f8d8d4..1834396 100755 --- a/script/borg-restore.pl +++ b/script/borg-restore.pl @@ -168,6 +168,9 @@ use File::Spec; use Getopt::Long; use Log::Any qw($log); use Log::Any::Adapter; +use Log::Log4perl; +use Log::Log4perl::Layout; +use Log::Log4perl::Level; use Pod::Usage; my $app; @@ -196,7 +199,19 @@ sub user_select_archive { } sub main { - Log::Any::Adapter->set('Stderr', log_level => "warn"); + my $appender = "Screen"; + $appender = "ScreenColoredLevels" if -t STDERR; ## no critic (InputOutput::ProhibitInteractiveTest) + + my $conf = " + log4perl.rootLogger = WARN, screenlog + + log4perl.appender.screenlog = Log::Log4perl::Appender::$appender + log4perl.appender.screenlog.stderr = 1 + log4perl.appender.screenlog.layout = Log::Log4perl::Layout::PatternLayout + log4perl.appender.screenlog.layout.ConversionPattern = %p %m%n + "; + Log::Log4perl::init( \$conf ); + Log::Any::Adapter->set('Log4perl'); my %opts; # untaint PATH because we only expect this to run as root @@ -209,7 +224,10 @@ sub main { pod2usage(0) if $opts{help}; if ($opts{debug}) { - Log::Any::Adapter->set('Stderr', log_level => "debug"); + my $logger = Log::Log4perl->get_logger(''); + $logger->level($DEBUG); + Log::Log4perl->appenders()->{"screenlog"}->layout( + Log::Log4perl::Layout::PatternLayout->new("%d %r [%30c:%-4L] %p %m%n")); } $app = App::BorgRestore->new(); |