Establish global logger object

Change-Id: Ia508e54e658f8d70921c0d7d52e48c710971807e
diff --git a/Makefile.PL b/Makefile.PL
index b055a82..918ef02 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -23,7 +23,8 @@
   PREREQ_PM => {
     'XML::CompactTree::XS'     => '0.03',
     'XML::LibXML::Reader' => '2.0201',
-    'IO::Compress::Zip' => '2.091'
+    'IO::Compress::Zip' => '2.091',
+    'Log::Any' => '1.708'
   },
   MIN_PERL_VERSION => '5.016',
   EXE_FILES => ['script/tei2korapxml']
diff --git a/lib/KorAP/XML/TEI/Header.pm b/lib/KorAP/XML/TEI/Header.pm
index 669c64b..9193928 100644
--- a/lib/KorAP/XML/TEI/Header.pm
+++ b/lib/KorAP/XML/TEI/Header.pm
@@ -1,6 +1,7 @@
 package KorAP::XML::TEI::Header;
 use strict;
 use warnings;
+use Log::Any qw($log);
 use Encode qw(encode decode);
 use KorAP::XML::TEI qw!escape_xml!;
 
@@ -41,7 +42,7 @@
 
   # Unexpected header init
   else {
-    die "ERROR ($0): Unable to parse header init '$text'";
+    die $log->fatal("Unable to parse header init '$text'");
     return;
   };
 
@@ -67,14 +68,11 @@
       # Add to text
       $self->[TEXT] .= $1;
 
-      die "ERROR ($0): main(): input line number $.: line with closing header tag '${_HEADER_TAG}'"
-        ." contains additional information ... => Aborting\n\tline=$_"
+      die $log->fatal("Line with tag '</${_HEADER_TAG}>' (L$.) contains additional information")
         if $2 !~ /^\s*$/;
 
       if ($self->dir eq '') {
-
-        print STDERR "WARNING ($0): main(): input line number $.: empty " . $sig_type .
-          " in header => nothing to do ...\n header=" . $self->[TEXT] . "\n";
+        $log->error("Empty '<$sig_type />' (L$.) in header");
         return;
 
       };
@@ -89,7 +87,7 @@
       my $sig = $2;
       my $sfx = $3;
 
-      die "ERROR ($0): main(): input line number $.: line with sigle-tag is not in expected format ... => Aborting\n\tline=$_"
+      die $log->fatal("line with '<$sig_type />' (L$.) is not in expected format")
         if $pfx !~ /^\s*$/  || $sfx !~ m!^</$sig_type>\s*$! || $sig =~ /^\s*$/;
 
       $self->[SIGLE] = encode('UTF-8' , $sig);
diff --git a/lib/KorAP/XML/TEI/Tokenizer.pm b/lib/KorAP/XML/TEI/Tokenizer.pm
index 331c8e4..3d1ba28 100644
--- a/lib/KorAP/XML/TEI/Tokenizer.pm
+++ b/lib/KorAP/XML/TEI/Tokenizer.pm
@@ -1,6 +1,7 @@
 package KorAP::XML::TEI::Tokenizer;
 use strict;
 use warnings;
+use Log::Any qw($log);
 
 # This is the base class for tokenizer objects.
 
@@ -34,7 +35,7 @@
   my ($self, $text_id) = @_;
 
   unless ($text_id) {
-    warn 'Missing textID';
+    $log->warn('Missing textID');
     return;
   };
 
diff --git a/lib/KorAP/XML/TEI/Tokenizer/External.pm b/lib/KorAP/XML/TEI/Tokenizer/External.pm
index 4fe3751..8456e97 100644
--- a/lib/KorAP/XML/TEI/Tokenizer/External.pm
+++ b/lib/KorAP/XML/TEI/Tokenizer/External.pm
@@ -2,6 +2,7 @@
 use base 'KorAP::XML::TEI::Tokenizer';
 use strict;
 use warnings;
+use Log::Any qw($log);
 use IO::Select;
 use IPC::Open2 qw(open2);
 
@@ -25,7 +26,7 @@
   #      " de.ids_mannheim.korap.tokenizer.KorAPTokenizerImpl"
 
   unless ($cmd) {
-    print STDERR "WARNING: tokenizer not established.\n";
+    $log->warn('Tokenizer not established');
     return;
   };
 
@@ -77,7 +78,7 @@
   }
 
   else {
-    print STDERR "WARNING: tokenizer can't be started.\n";
+    $log->error('Tokenizer can\'t be started');
   };
 };
 
@@ -97,7 +98,7 @@
   my ($self, $text_id) = @_;
 
   unless ($text_id) {
-    warn 'Missing textID';
+    $log->warn('Missing textID');
     return;
   };
 
@@ -130,17 +131,17 @@
       $_ = <$out>;
 
       if (defined $_ && $_ ne '') {
-        print STDERR "WARNING: extra output: $_\n"
+        $log->warn("Extra output: $_");
       }
       else {
-        print STDERR "WARNING: tokenizer seems to have crashed, restarting.\n";
+        $log->warn('Tokenizer seems to have crashed, restarting');
         $self->reset;
       };
     };
   }
 
   else {
-    die "ERROR ($0): cannot retrieve token bounds from external tokenizer for text '$text_id' => Aborting ...\n";
+    die $log->fatal("Can\'t retrieve token bounds from external tokenizer ('$text_id')");
   };
 
   # Add footer
diff --git a/lib/KorAP/XML/TEI/Zipper.pm b/lib/KorAP/XML/TEI/Zipper.pm
index dd0c698..c6d5143 100644
--- a/lib/KorAP/XML/TEI/Zipper.pm
+++ b/lib/KorAP/XML/TEI/Zipper.pm
@@ -1,6 +1,7 @@
 package KorAP::XML::TEI::Zipper;
 use strict;
 use warnings;
+use Log::Any qw($log);
 use IO::Compress::Zip qw($ZipError :constants);
 
 # man IO::Compress::Zip
@@ -36,7 +37,7 @@
       Method => $_COMPRESSION_METHOD,
       Append => 0,
       Name => "$file"
-    ) or die "ERROR ('$file'): zip failed: $ZipError\n"
+    ) or die $log->fatal("Zipping $file failed: $ZipError");
   }
 
   # Close existing stream and open a new one
@@ -47,7 +48,7 @@
       Method => $_COMPRESSION_METHOD,
       Append => 1,
       Name => "$file"
-    ) or die "ERROR ('$file'): zip failed: $ZipError\n"
+    ) or die $log->fatal("Zipping $file failed: $ZipError");
   };
 
   return $self->[1];