Replaced Log4perl with Log::Any
Change-Id: I0837fb628fcfffef1edc5e497819b6f6966cf292
diff --git a/Changes b/Changes
index 0bdeb59..2adee64 100644
--- a/Changes
+++ b/Changes
@@ -1,4 +1,7 @@
-0.41 2020-10-30
+0.42 2020-11-03
+ - Replaced Log4perl with Log::Any.
+
+0.41 2020-08-10
- Added support for RWK annotations.
- Improved DGD support.
- Fixed bug in RWK support that broke on
diff --git a/Makefile.PL b/Makefile.PL
index 4b5f759..02bc475 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -14,7 +14,7 @@
'Mojolicious' => 7.23,
'Packed::Array' => 0.01,
'Test::Output' => 0,
- 'Log::Log4perl' => 1.42,
+ 'Log::Any' => 1.708,
'JSON::XS' => 3.01,
'Set::Scalar' => 1.26,
'XML::Fast' => 0.11,
diff --git a/lib/KorAP/XML/Batch/File.pm b/lib/KorAP/XML/Batch/File.pm
index 5c1bea9..297fc06 100644
--- a/lib/KorAP/XML/Batch/File.pm
+++ b/lib/KorAP/XML/Batch/File.pm
@@ -1,6 +1,7 @@
package KorAP::XML::Batch::File;
use KorAP::XML::Krill;
-use Mojo::Log;
+# use Mojo::Log;
+use Log::Any qw($log);
use IO::Compress::Gzip;
use IO::File;
use strict;
@@ -18,7 +19,7 @@
foundry => $param{foundry} || 'Base',
layer => $param{layer} || 'Tokens',
anno => $param{anno} || [[]],
- log => $param{log} || Mojo::Log->new(level => 'fatal'),
+ log => $param{log} || $log,
koral => $param{koral},
non_word_tokens => $param{non_word_tokens},
non_verbal_tokens => $param{non_verbal_tokens},
@@ -193,7 +194,7 @@
=item log
-A L<Mojo::Log> compatible log object.
+A L<Log::Any> compatible log object.
=item gzip
diff --git a/lib/KorAP/XML/Krill.pm b/lib/KorAP/XML/Krill.pm
index 58d8c05..17741f1 100644
--- a/lib/KorAP/XML/Krill.pm
+++ b/lib/KorAP/XML/Krill.pm
@@ -8,8 +8,7 @@
use Try::Tiny;
use KorAP::XML::Document::Primary;
use KorAP::XML::Tokenizer;
-use Log::Log4perl;
-use KorAP::XML::Log;
+use Log::Any qw($log);
use Cache::FastMmap;
use Mojo::DOM;
use File::Spec::Functions qw/catdir catfile catpath splitdir splitpath rel2abs/;
@@ -17,8 +16,7 @@
our @EXPORT_OK = qw(get_file_name get_file_name_from_glob);
-
-our $VERSION = '0.41';
+our $VERSION = '0.42';
has 'path';
has [qw/text_sigle doc_sigle corpus_sigle/];
@@ -26,10 +24,6 @@
has 'cache';
has log => sub {
- if(Log::Log4perl->initialized()) {
- state $log = Log::Log4perl->get_logger(__PACKAGE__);
- };
- state $log = KorAP::XML::Log->new;
return $log;
};
@@ -64,7 +58,7 @@
# No primary data found
unless (-e $data_xml) {
- $self->log->warn($unable . ' - no data.xml found');
+ $log->warn($unable . ' - no data.xml found');
$error = 1;
}
@@ -80,14 +74,14 @@
$rt = xml2hash($file, text => '#text', attr => '-')->{raw_text};
} catch {
- $self->log->warn($unable);
+ $log->warn($unable);
$error = 1;
};
};
return if $error;
- $self->log->debug('Parse document ' . $self->path);
+ $log->debug('Parse document ' . $self->path);
# Get document id and corpus id
if ($rt && $rt->{'-docid'}) {
@@ -97,12 +91,12 @@
$self->corpus_sigle($1);
}
else {
- $self->log->warn($unable . ': ID not parseable: ' . $rt->{'-docid'});
+ $log->warn($unable . ': ID not parseable: ' . $rt->{'-docid'});
return;
};
}
else {
- $self->log->warn($unable . ': No raw_text found or no ID');
+ $log->warn($unable . ': No raw_text found or no ID');
return;
};
@@ -116,7 +110,7 @@
my $pd = html_unescape substr($file, $start, $end - $start);
unless ($pd) {
- $self->log->warn($unable . ': No primary data found');
+ $log->warn($unable . ': No primary data found');
return;
};
@@ -142,7 +136,7 @@
if ($meta_class->can('new') || eval("require $meta_class; 1;")) {
$meta = $meta_class->new(
- log => $self->log,
+ log => $log,
corpus_sigle => $self->corpus_sigle,
doc_sigle => $self->doc_sigle,
text_sigle => $self->text_sigle,
@@ -154,7 +148,7 @@
};
unless ($meta) {
- $self->log->warn(
+ $log->warn(
"Metadata object for $meta_data_type not initializable"
);
};
@@ -205,7 +199,7 @@
# Parse tokens
unless ($tokens->parse) {
- $self->log->warn(
+ $log->warn(
'Unable to tokenize ' . $self->path .
' with ' . $token_foundry . '#'
. $token_layer
@@ -224,7 +218,7 @@
sub annotate {
my $self = shift;
unless ($self->{tokenizer}) {
- $self->log->warn('No tokenizer defined')
+ $log->warn('No tokenizer defined')
}
else {
$self->{tokenizer}->add(@_);
@@ -294,7 +288,7 @@
sub to_json {
my $self = shift;
unless ($self->{tokenizer}) {
- $self->log->warn('No tokenizer defined');
+ $log->warn('No tokenizer defined');
return;
};
@@ -372,7 +366,7 @@
=head2 log
-L<Log::Log4perl> object for logging.
+L<Log::Any> object for logging.
=head2 path
diff --git a/lib/KorAP/XML/Meta/Base.pm b/lib/KorAP/XML/Meta/Base.pm
index 4a61d87..d0afe93 100644
--- a/lib/KorAP/XML/Meta/Base.pm
+++ b/lib/KorAP/XML/Meta/Base.pm
@@ -1,5 +1,6 @@
package KorAP::XML::Meta::Base;
-use Mojo::Log;
+# use Mojo::Log;
+use Log::Any qw($log);
use strict;
use warnings;
@@ -20,7 +21,7 @@
sub log {
return $_[0]->{_log} if $_[0]->{_log};
- $_[0]->{_log} = Mojo::Log->new;
+ $_[0]->{_log} = $log;
};
sub corpus_sigle {
diff --git a/lib/KorAP/XML/Tokenizer.pm b/lib/KorAP/XML/Tokenizer.pm
index 7e72968..3496d69 100644
--- a/lib/KorAP/XML/Tokenizer.pm
+++ b/lib/KorAP/XML/Tokenizer.pm
@@ -15,7 +15,7 @@
use Unicode::Normalize qw/getCombinClass normalize/;
use List::MoreUtils 'uniq';
use JSON::XS;
-use Log::Log4perl;
+use Log::Any qw($log);
# TODO 1:
# Bei den Autoren im Index darauf achten,
@@ -40,11 +40,6 @@
has 'error';
has log => sub {
- if (Log::Log4perl->initialized()) {
- state $log = Log::Log4perl->get_logger(__PACKAGE__);
- return $log;
- };
- state $log = KorAP::XML::Log->new;
return $log;
};
@@ -64,7 +59,7 @@
unless (-e $path) {
$self->error('Unable to load base tokenization: ' . $path);
- $self->log->warn($self->error);
+ $log->warn($self->error);
return;
};
@@ -80,7 +75,7 @@
my $old = 0;
- $self->log->trace('Tokenize data ' . $self->foundry . ':' . $self->layer);
+ $log->trace('Tokenize data ' . $self->foundry . ':' . $self->layer);
# TODO: Reuse the following code from Spans.pm and Tokens.pm
my ($tokens, $error);
@@ -98,7 +93,7 @@
} catch {
$self->error('Token error in ' . $path . ($_ ? ': ' . $_ : ''));
- $self->log->warn($self->error);
+ $log->warn($self->error);
};
return if $error;
@@ -131,7 +126,7 @@
# Token is undefined
unless (defined $token) {
$self->error("Tokenization with failing offsets in $path");
- $self->log->warn("Unable to find substring [$from-$to] in $path");
+ $log->warn("Unable to find substring [$from-$to] in $path");
return;
};
@@ -225,7 +220,7 @@
$self->should($should);
$self->have($have);
- $self->log->debug('With a non-word quota of ' . _perc($self->should, $self->should - $self->have) . ' %');
+ $log->debug('With a non-word quota of ' . _perc($self->should, $self->should - $self->have) . ' %');
return $self;
};
@@ -298,13 +293,13 @@
my %param = @_;
unless ($self->stream) {
- $self->log->warn(
+ $log->warn(
'No token data available'
);
return;
};
- $self->log->trace(
+ $log->trace(
($param{skip} ? 'Skip' : 'Add').' span data '.$param{foundry}.':'.$param{layer}
);
@@ -325,12 +320,12 @@
my $spanarray = $spans->parse or return;
- if ($self->log->is_debug) {
+ if ($log->is_debug) {
if ($spans->should == $spans->have) {
- $self->log->trace('With perfect alignment!');
+ $log->trace('With perfect alignment!');
}
else {
- $self->log->debug('With an alignment quota of ' . _perc($spans->should, $spans->have) . ' %');
+ $log->debug('With an alignment quota of ' . _perc($spans->should, $spans->have) . ' %');
};
};
@@ -349,13 +344,13 @@
my %param = @_;
unless ($self->stream) {
- $self->log->warn(
+ $log->warn(
'No token data available'
);
return;
};
- $self->log->trace(
+ $log->trace(
($param{skip} ? 'Skip' : 'Add').' token data '.$param{foundry}.':'.$param{layer}
);
return if $param{skip};
@@ -376,15 +371,15 @@
# Output some debug information
# on token alignment
- if ($self->log->is_debug) {
+ if ($log->is_debug) {
if ($tokens->should == $tokens->have) {
- $self->log->trace('With perfect alignment!');
+ $log->trace('With perfect alignment!');
}
else {
my $perc = _perc(
$tokens->should, $tokens->have, $self->should, $self->should - $self->have
);
- $self->log->debug('With an alignment quota of ' . $perc);
+ $log->debug('With an alignment quota of ' . $perc);
};
};
@@ -408,7 +403,7 @@
my $layer = shift;
unless ($foundry && $layer) {
- $self->log->warn('Unable to add specific module - not enough information given!');
+ $log->warn('Unable to add specific module - not enough information given!');
return;
};
@@ -427,11 +422,11 @@
return $retval;
}
else {
- $self->log->debug('Unable to parse '.$mod);
+ $log->debug('Unable to parse '.$mod);
};
}
else {
- $self->log->warn('Unable to load '.$mod . '(' . $@ . ')');
+ $log->warn('Unable to load '.$mod . '(' . $@ . ')');
};
return;
diff --git a/lib/KorAP/XML/Tokenizer/Spans.pm b/lib/KorAP/XML/Tokenizer/Spans.pm
index 2722aec..281013e 100644
--- a/lib/KorAP/XML/Tokenizer/Spans.pm
+++ b/lib/KorAP/XML/Tokenizer/Spans.pm
@@ -1,7 +1,6 @@
package KorAP::XML::Tokenizer::Spans;
use strict;
use warnings;
-use KorAP::XML::Log;
use Data::Dumper;
use Mojo::Base 'KorAP::XML::Tokenizer::Units';
use Mojo::File;
@@ -9,15 +8,12 @@
use Mojo::ByteStream 'b';
use XML::Fast;
use Try::Tiny;
+use Log::Any qw($log);
has 'range';
has 'log' => sub {
- if(Log::Log4perl->initialized()) {
- state $log = Log::Log4perl->get_logger(__PACKAGE__);
- };
- state $log = KorAP::XML::Log->new;
- return $log;
+ $log;
};
diff --git a/lib/KorAP/XML/Tokenizer/Tokens.pm b/lib/KorAP/XML/Tokenizer/Tokens.pm
index 50367d4..78e3f8e 100644
--- a/lib/KorAP/XML/Tokenizer/Tokens.pm
+++ b/lib/KorAP/XML/Tokenizer/Tokens.pm
@@ -6,9 +6,10 @@
use File::Spec::Functions qw/catdir catfile/;
use XML::Fast;
use Try::Tiny;
+use Log::Any qw($log);
has 'log' => sub {
- Log::Log4perl->get_logger(__PACKAGE__)
+ $log;
};
sub parse {
@@ -50,7 +51,7 @@
};
$spans = xml2hash($file, text => '#text', attr => '-')->{layer}->{spanList};
} catch {
- $self->log->warn('Span error in ' . $path . ($_ ? ': ' . $_ : ''));
+ $log->warn('Span error in ' . $path . ($_ ? ': ' . $_ : ''));
$error = 1;
};
diff --git a/script/korapxml2krill b/script/korapxml2krill
index 9b79b47..ab68d96 100644
--- a/script/korapxml2krill
+++ b/script/korapxml2krill
@@ -9,7 +9,8 @@
use Benchmark qw/:hireswallclock/;
use IO::Compress::Gzip qw/$GzipError/;
use POSIX qw/ceil/;
-use Log::Log4perl;
+use Log::Any qw($log);
+use Log::Any::Adapter;
use Pod::Usage;
use Cache::FastMmap;
use Directory::Iterator;
@@ -152,7 +153,7 @@
# - Added support for Redewiedergabe-Korpus morphology
# ----------------------------------------------------------
-our $LAST_CHANGE = '2020/08/07';
+our $LAST_CHANGE = '2020/10/21';
our $LOCAL = $FindBin::Bin;
our $KORAL_VERSION = 0.03;
our $VERSION_MSG = <<"VERSION";
@@ -293,15 +294,9 @@
my %skip;
$skip{lc($_)} = 1 foreach @skip;
-# Initialize log4perl object
-Log::Log4perl->init({
- 'log4perl.rootLogger' => uc($cfg{log} // 'ERROR') . ', STDERR',
- 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
- 'log4perl.appender.STDERR.layout' => 'PatternLayout',
- 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
-});
-
-my $log = Log::Log4perl->get_logger('main');
+Log::Any::Adapter->set(
+ 'Stderr', log_level => uc($cfg{log} // 'ERROR')
+);
if ($cmd && $output && (!defined($to_tar)) && (!-e $output || !-d $output)) {
$log->error("Directory '$output' does not exist.");
@@ -1321,7 +1316,7 @@
=item B<--log|-l>
-The L<Log4perl> log level, defaults to C<ERROR>.
+The L<Log::Any> log level, defaults to C<ERROR>.
=item B<--help|-h>
diff --git a/t/annotation/malt_dependency.t b/t/annotation/malt_dependency.t
index cbbbf27..44a4a11 100644
--- a/t/annotation/malt_dependency.t
+++ b/t/annotation/malt_dependency.t
@@ -3,15 +3,6 @@
use warnings;
use KorAP::XML::Annotation::Malt::Dependency;
use utf8;
-use Log::Log4perl;
-
-Log::Log4perl->init({
- 'log4perl.rootLogger' => 'ERROR, STDERR',
- 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
- 'log4perl.appender.STDERR.layout' => 'PatternLayout',
- 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
-});
-
use Test::More;
use Scalar::Util qw/weaken/;
use Data::Dumper;
diff --git a/t/annotation/mdp_dependency.t b/t/annotation/mdp_dependency.t
index 2fd341f..f7f29a2 100644
--- a/t/annotation/mdp_dependency.t
+++ b/t/annotation/mdp_dependency.t
@@ -2,16 +2,7 @@
use strict;
use warnings;
use utf8;
-use Log::Log4perl;
use Data::Dumper;
-
-Log::Log4perl->init({
- 'log4perl.rootLogger' => 'ERROR, STDERR',
- 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
- 'log4perl.appender.STDERR.layout' => 'PatternLayout',
- 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
-});
-
use File::Basename 'dirname';
use File::Spec::Functions qw/catdir catfile/;
use Test::More;
diff --git a/t/real/agd.t b/t/real/agd.t
index ebb658b..c1f8cc5 100644
--- a/t/real/agd.t
+++ b/t/real/agd.t
@@ -3,7 +3,6 @@
use Test::More;
use Data::Dumper;
use JSON::XS;
-use Log::Log4perl;
use utf8;
if ($ENV{SKIP_REAL}) {
@@ -14,15 +13,6 @@
my $t = Benchmark->new;
-# Initialize log4perl object
-#Log::Log4perl->init({
-# 'log4perl.rootLogger' => 'TRACE, STDERR',
-# 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
-# 'log4perl.appender.STDERR.layout' => 'PatternLayout',
-# 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
-#});
-
-
use File::Basename 'dirname';
use File::Spec::Functions 'catdir';
diff --git a/t/real/bzk.t b/t/real/bzk.t
index 8636fb9..8c0d16e 100644
--- a/t/real/bzk.t
+++ b/t/real/bzk.t
@@ -3,7 +3,6 @@
use Test::More;
use Data::Dumper;
use JSON::XS;
-use Log::Log4perl;
if ($ENV{SKIP_REAL}) {
plan skip_all => 'Skip real tests';
@@ -16,13 +15,6 @@
use utf8;
use lib 'lib', '../lib';
-#Log::Log4perl->init({
-# 'log4perl.rootLogger' => 'DEBUG, STDERR',
-# 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
-# 'log4perl.appender.STDERR.layout' => 'PatternLayout',
-# 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
-#});
-
use File::Basename 'dirname';
use File::Spec::Functions 'catdir';
diff --git a/t/real/ngafc.t b/t/real/ngafc.t
index 04eb4a1..95eabc4 100644
--- a/t/real/ngafc.t
+++ b/t/real/ngafc.t
@@ -13,7 +13,6 @@
use Test::More;
use Data::Dumper;
use JSON::XS;
-use Log::Log4perl;
if ($ENV{SKIP_REAL}) {
plan skip_all => 'Skip real tests';
diff --git a/t/real/rei.t b/t/real/rei.t
index ab3df72..6593258 100644
--- a/t/real/rei.t
+++ b/t/real/rei.t
@@ -3,7 +3,6 @@
use Test::More;
use Data::Dumper;
use JSON::XS;
-use Log::Log4perl;
if ($ENV{SKIP_REAL}) {
plan skip_all => 'Skip real tests';
@@ -15,14 +14,6 @@
use File::Basename 'dirname';
use File::Spec::Functions 'catdir';
-# Initialize log4perl object
-Log::Log4perl->init({
- 'log4perl.rootLogger' => 'ERROR, STDERR',
- 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
- 'log4perl.appender.STDERR.layout' => 'PatternLayout',
- 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
-});
-
use_ok('KorAP::XML::Krill');
my $path = catdir(dirname(__FILE__), 'corpus','REI','BNG','00128');
diff --git a/t/real/rwk.t b/t/real/rwk.t
index 7e5642d..efc0b94 100644
--- a/t/real/rwk.t
+++ b/t/real/rwk.t
@@ -3,7 +3,6 @@
use Test::More;
use Data::Dumper;
use JSON::XS;
-use Log::Log4perl;
if ($ENV{SKIP_REAL}) {
plan skip_all => 'Skip real tests';
@@ -15,14 +14,6 @@
use File::Basename 'dirname';
use File::Spec::Functions 'catdir';
-# Initialize log4perl object
-Log::Log4perl->init({
- 'log4perl.rootLogger' => 'ERROR, STDERR',
- 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
- 'log4perl.appender.STDERR.layout' => 'PatternLayout',
- 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
-});
-
use_ok('KorAP::XML::Krill');
my $path = catdir(dirname(__FILE__), 'corpus','REDEW','DOC1','00000');
@@ -200,16 +191,6 @@
is(substr($output->{data}->{text}, 0, 100), 'Er hatte den Kopf weit nach rückwärts gebeugt, seine langen schwarzen Haare lockten sich über den li', 'Primary Data');
-use Log::Log4perl;
-
-Log::Log4perl->init({
- 'log4perl.rootLogger' => 'WARN, STDERR',
- 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
- 'log4perl.appender.STDERR.layout' => 'PatternLayout',
- 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
-});
-
-
# Add annotations
ok($tokens->add('RWK', 'Morpho'));
ok($tokens->add('RWK', 'Structure'));
@@ -286,16 +267,6 @@
is(substr($output->{data}->{text}, 0, 100), 'Er hatte den Kopf weit nach rückwärts gebeugt, seine langen schwarzen Haare lockten sich über den li', 'Primary Data');
-use Log::Log4perl;
-
-Log::Log4perl->init({
- 'log4perl.rootLogger' => 'WARN, STDERR',
- 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
- 'log4perl.appender.STDERR.layout' => 'PatternLayout',
- 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
-});
-
-
# Add annotations
ok($tokens->add('RWK', 'Morpho'));
ok($tokens->add('RWK', 'Structure'));
diff --git a/t/real/wdd.t b/t/real/wdd.t
index 57dcbc7..779a44e 100644
--- a/t/real/wdd.t
+++ b/t/real/wdd.t
@@ -1,4 +1,4 @@
-#use strict;
+use strict;
use warnings;
use Test::More;
use Data::Dumper;
@@ -293,14 +293,6 @@
);
ok($tokens, 'Token Object is fine');
-# Initialize log4perl object
-Log::Log4perl->init({
- 'log4perl.rootLogger' => 'DEBUG, STDERR',
- 'log4perl.appender.STDERR' => 'Log::Log4perl::Appender::ScreenColoredLevels',
- 'log4perl.appender.STDERR.layout' => 'PatternLayout',
- 'log4perl.appender.STDERR.layout.ConversionPattern' => '[%r] %F %L %c - %m%n'
-});
-
ok(!$tokens->parse, 'Token parsing is fine');