Skip to content

Commit

Permalink
better logging info (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
matyaskopp committed Apr 1, 2021
1 parent 4f77463 commit ff692e5
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/incidents/incidents.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use File::Spec;


use ParCzech::PipeLine::FileManager;
use ParCzech::PipeLine::FileManager "incidents";
use ParCzech::NoteClassifier;

my $scriptname = $0;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ParCzech/NER/CNEC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ParCzech::NER::CNEC;

use warnings;
use strict;
use ParCzech::PipeLine::FileManager;
use ParCzech::PipeLine::FileManager __PACKAGE__;

my $namedEntities = {
valuesname => 'class',
Expand Down
11 changes: 11 additions & 0 deletions src/lib/ParCzech/PipeLine/FileManager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use strict;
use open qw(:std :utf8);
use utf8;
use File::Spec;
use ParCzech::PipeLine::Logger;

our $logger;

my ($lock_result,$input_file,$output_file,$filelist);
my $input_dir = './';
Expand All @@ -13,6 +16,12 @@ my $output_dir = './';

my @files;


sub import {
my ($package, $msg) = @_;
$logger = ParCzech::PipeLine::Logger->new(prefix => $msg // __PACKAGE__);
}

sub opts {(
'lock-result' => \$lock_result,
# single file input
Expand Down Expand Up @@ -381,6 +390,7 @@ sub open_xml {
my %vars = @_;
my $xml;
local $/;
$ParCzech::PipeLine::FileManager::logger->log_line('opening',$file);
open FILE, $file;
binmode ( FILE, ":utf8" );
my $rawxml = <FILE>;
Expand Down Expand Up @@ -449,6 +459,7 @@ sub save_to_file {
evaluate_vars(\$raw,$log,%vars);
print FILE $raw;
close FILE;
$ParCzech::PipeLine::FileManager::logger->log_line('saved to',$filename);
return [map {[$filename,@$_]} @$log];
}

Expand Down
35 changes: 35 additions & 0 deletions src/lib/ParCzech/PipeLine/Logger.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ParCzech::PipeLine::Logger;

use warnings;
use strict;
use open qw(:std :utf8);
use utf8;
use DateTime;


sub new {
my $this = shift;
my $class = ref($this) || $this;
my %opts = @_;
my $self = {};
bless $self, $class;
$self->{prefix} = $opts{prefix} if defined $opts{prefix};
$self->{tz} = DateTime::TimeZone->new( name => 'local' ) // DateTime::TimeZone->new( name => 'floating' ) // DateTime::TimeZone->new( name => 'UTC' );
return $self
}


sub log_line {
my $self = shift;
my $date = DateTime->now(time_zone => $self->{tz})->strftime('%Y-%m-%d %T');
print STDERR "$date\t",$self->get_prefix,join(' ',@_),"\n";
}

sub get_prefix {
my $self = shift;
return '' unless defined $self->{prefix};
return "($self->{prefix}) ";
}


1;
2 changes: 1 addition & 1 deletion src/lib/ParCzech/XMLmerge.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use utf8;
use File::Spec;
use File::Copy;
use XML::LibXML qw(:libxml);
use ParCzech::PipeLine::FileManager;
use ParCzech::PipeLine::FileManager __PACKAGE__;
use ParCzech::XMLmerge::teiCorpus;
use sort 'stable'; # guarantee stability

Expand Down
2 changes: 1 addition & 1 deletion src/metadater/metadater.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use File::Spec;


use ParCzech::PipeLine::FileManager;
use ParCzech::PipeLine::FileManager "metadater";

my $scriptname = $0;
my $dirname = dirname($scriptname);
Expand Down
2 changes: 1 addition & 1 deletion src/nametag2/nametag2.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use LWP::UserAgent;
use JSON;

use ParCzech::PipeLine::FileManager;
use ParCzech::PipeLine::FileManager "nametag";

my $scriptname = $0;

Expand Down
2 changes: 1 addition & 1 deletion src/psp-db/pspdb-generate-xml.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Getopt::Long;
use File::Spec;
use DateTime::Format::Strptime;
use ParCzech::PipeLine::FileManager;
use ParCzech::PipeLine::FileManager "psp-db";
use ParCzech::Translation;
use DBI;
use Unicode::Diacritic::Strip;
Expand Down
2 changes: 1 addition & 1 deletion src/udpipe2/udpipe2.pl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use File::Spec;


use ParCzech::PipeLine::FileManager;
use ParCzech::PipeLine::FileManager "udpipe";

my $scriptname = $0;
my $dirname = dirname($scriptname);
Expand Down

0 comments on commit ff692e5

Please sign in to comment.