From 09e62987958233366e0852d83e8eb6de5d5e7b81 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Thu, 6 Mar 2014 11:16:24 +1300 Subject: [PATCH] Starting work on better logging using Log::Log4perl --- lib/NCIP.pm | 8 +++++--- t/config_sample/log4perl.conf | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 t/config_sample/log4perl.conf diff --git a/lib/NCIP.pm b/lib/NCIP.pm index bf23910..364f063 100644 --- a/lib/NCIP.pm +++ b/lib/NCIP.pm @@ -6,6 +6,7 @@ use XML::LibXML; use Try::Tiny; use Module::Load; use Template; +use Log::Log4perl; use Object::Tiny qw{xmldoc config namespace ils}; @@ -33,7 +34,7 @@ sub new { my $config = NCIP::Configuration->new($config_dir); $self->{config} = $config; $self->{namespace} = $config->('NCIP.namespace.value'); - + Log::Log4perl->init($config_dir . "/log4perl.conf"); # load the ILS dependent module my $module = 'NCIP::ILS::' . $config->('NCIP.ils.value'); load $module || die "Can not load ILS module $module"; @@ -80,9 +81,10 @@ sub handle_initiation { my $self = shift; my $xml = shift; my $dom; + my $log = Log::Log4perl->get_logger("NCIP"); eval { $dom = XML::LibXML->load_xml( string => $xml ); }; if ($@) { - warn "Invalid xml, caught error: $@"; + $log->info("Invalid xml we can not parse it "); } if ($dom) { @@ -104,7 +106,7 @@ sub handle_initiation { } } else { - warn "We have no DOM"; + $log->info("We have no DOM"); return; } diff --git a/t/config_sample/log4perl.conf b/t/config_sample/log4perl.conf new file mode 100644 index 0000000..4f844d6 --- /dev/null +++ b/t/config_sample/log4perl.conf @@ -0,0 +1,12 @@ +############################################################ +# A simple root logger with a Log::Log4perl::Appender::File +# file appender in Perl. +############################################################ +log4perl.rootLogger=DEBUG, LOGFILE + +log4perl.appender.LOGFILE=Log::Log4perl::Appender::File +log4perl.appender.LOGFILE.filename=/tmp/ncip.log +log4perl.appender.LOGFILE.mode=append + +log4perl.appender.LOGFILE.layout=PatternLayout +log4perl.appender.LOGFILE.layout.ConversionPattern=[%r] %F %L %c - %m%n -- 2.43.2