Use Log::Any script-wide and support log level parameter

Change-Id: Iff68a533577663c1038cd0cad740e8ad45cb3255
diff --git a/script/tei2korapxml b/script/tei2korapxml
index 280cacc..da2cec6 100755
--- a/script/tei2korapxml
+++ b/script/tei2korapxml
@@ -2,6 +2,8 @@
 use strict;
 use warnings;
 
+use Log::Any '$log';
+use Log::Any::Adapter;
 use Pod::Usage;
 use Getopt::Long qw(GetOptions :config no_auto_abbrev);
 
@@ -38,6 +40,7 @@
   "input|i=s" => \(my $input_fname = ''), # input file (yet only TEI I5 Format accepted)
   'tokenizer-call|tc=s' => \(my $tokenizer_call), # Temporary argument for testing purposes
   'use-intern-tokenization|ti' => \(my $tokenizer_intern), # use intern tokenization (default = no)
+  'log|l=s' => \(my $log_level = 'notice'),
   'help|h'    => sub {
     pod2usage(
       -verbose => 99,
@@ -55,6 +58,8 @@
   }
 );
 
+Log::Any::Adapter->set('Stderr', log_level => $log_level);
+
 #
 # ~~~ parameter (mandatory) ~~~
 #
@@ -348,7 +353,9 @@
         # which are counted as 1 (search for '&' in data.xml and see
         # corresponding indices in $_tokens_file)
 
-        print STDERR "DEBUG ($0): main(): Writing (utf8-formatted) xml file $_root_dir$dir/$_data_file\n" if $_DEBUG;
+        if ($_DEBUG) {
+          $log->debug("Writing (utf8-formatted) xml file $_root_dir$dir/$_data_file");
+        };
 
         $zipper->new_stream("$_root_dir$dir/$_data_file")
           ->print("$data_prfx1$text_id_esc$data_prfx2$data$data_sfx");
@@ -373,10 +380,7 @@
         $data_fl = 0; $buf_in = $data = $dir = ""; # reinit.
 
       } else { # $dir eq ""
-
-        print STDERR "WARNING ($0): main(): maybe empty textSigle => skipping this text ...\n";
-        # print STDERR "WARNING ($0): main(): text header=$header_txt\n";
-        print STDERR "WARNING ($0): main(): data=$data\n";
+        $log->warn("Maybe empty textSigle => skipping this text ...\ndata=$data");
       }
 
     } elsif ( $data_fl ){
@@ -465,7 +469,7 @@
         # Write header to zip
         my $file = $_root_dir . $header->dir . '/' . $_header_file;
 
-        print STDERR "DEBUG ($0): Writing file $file\n" if $_DEBUG;
+        $log->debug("Writing file $file") if $_DEBUG;
 
         $header->to_zip($zipper->new_stream($file));
 
@@ -478,7 +482,7 @@
           $text_id_esc = $header->id_esc;
 
           # log output for seeing progression
-          print STDERR "$0: main(): text_id=".decode("UTF-8", $text_id )."\n";
+          $log->notice("$0: main(): text_id=".decode('UTF-8', $text_id ));
 
           $tl = 0; # reset (needed for ~ whitespace handling ~)
         };
@@ -869,8 +873,7 @@
   #print STDERR "$0: write_structures(): ...\n";
 
   if ( $dir eq "" ){
- 
-   print STDERR "WARNING ($0): write_structures(): empty textSigle => nothing to do ...\n";
+    $log->warn("write_structures(): empty textSigle => nothing to do ...");
     return;
   }
 
@@ -1061,6 +1064,10 @@
 that will take an I<Aggressive> and a I<conservative>
 approach.
 
+=item B<--log|-l>
+
+Loglevel for I<Log::Any>. Defaults to C<notice>.
+
 =back
 
 =head1 COPYRIGHT AND LICENSE