Commit 9e1f5fe8 authored by Stefan Tauner's avatar Stefan Tauner
Browse files

Unify log startup in all applications

parent f46cdc30
......@@ -3,10 +3,12 @@ use strict;
use warnings;
use Log::Log4perl qw(get_logger);
use Log::Log4perl::Level;
use File::Basename qw(basename);
use Cwd 'realpath';
use if $^O eq "MSWin32", 'Win32::TieRegistry';
use if $^O eq "MSWin32", 'File::DosGlob' => qw(glob);
use if $^O ne "MSWin32", 'File::Glob' => qw(:bsd_glob);
use FIJI qw(:fiji_version);
use Data::Dumper;
......@@ -108,6 +110,35 @@ sub execute_completion_script {
}
}
# @function log_start($load_config, $use_string_buffer, ...)
# Initializes the logger and logs application parameters
#
# @param load_config (Re-)Load the logger configuration from a file.
# @param use_string_buffer The default logger configuration saves all log lines into
# a buffer to make it available to the application. This
# option allows for explicitly disabling this buffer.
# @param ... @ARGV
sub log_start {
my $load_config = shift;
my $use_string_buffer = shift;
if ($load_config) {
my $log_conf = File::Spec->catfile($FindBin::Bin, 'logger.conf');
Log::Log4perl::init_and_watch($log_conf, 'HUP');
}
# No need for buffered log output?
if (!$use_string_buffer) {
Log::Log4perl->eradicate_appender("string");
}
my $name = basename($0);
$name =~ s/\.p[lm]//;
my $logger = get_logger("");
my $fiji_version = FIJI_VERSION;
$logger->info("=== Starting new execution of $name $fiji_version ===");
$logger->info(sprintf("%d argument(s)%s", scalar(@_), scalar(@_) > 0 ? ": @_" : ""));
}
sub add_appender {
my $logger = get_logger("");
my ($custom_appender, $log4p_level) = @_;
......
......@@ -48,18 +48,8 @@ my $prob = {};
my $dur = {};
sub main {
my $log_conf = File::Spec->catfile($FindBin::Bin, 'logger.conf');
Log::Log4perl::init_and_watch($log_conf, 'HUP');
FIJI::Utils::increase_verbosity($cfg->{'verbosity_delta'});
my $logger = get_logger("");
my $name = $0;
$name =~ s/\.p[lm]//;
my $fiji_version = FIJI_VERSION;
$logger->info("=== Starting new execution of $name $fiji_version ===");
$logger->info(sprintf("%d argument(s)%s", scalar(@_), scalar(@_) > 0 ? ": @_" : ""));
my ($cfg,$prob,$dur) = @_;
pod2usage(0) if (defined $cfg->{'help'});
# Validate parameters
......@@ -72,6 +62,8 @@ sub main {
pod2usage(-exitval=>1,-msg=>$msg,-verbose);
}
FIJI::Utils::increase_verbosity($cfg->{'verbosity_delta'});
# Do our own globbing because the shell does not glob
# when the filename is passed with --long-option=PATH
foreach my $k ('settings_name','tests_name') {
......@@ -170,6 +162,8 @@ sub _ask_save {
return $tests->export_tb($filename,$fiji_downloader->{'fiji_settings'}) if $save_mode eq TB;
}
FIJI::Utils::log_start(1, 1, @ARGV);
GetOptions(
"m|mode=s" => \($cfg->{'mode'}),
"s|settings=s" => \($cfg->{'settings_name'}),
......@@ -192,7 +186,7 @@ GetOptions(
)
or pod2usage(-exitval=>1,-verbose=>1);
exit main($cfg,$prob,$dur);
exit main();
__END__
......
......@@ -52,7 +52,7 @@ use Pod::Usage;
# undef => classic+menu GUI
use constant USE_MENU => undef;
use FIJI qw(:default :fiji_dir :fiji_version);
use FIJI qw(:default :fiji_dir);
use FIJI::Tests;
use FIJI::Downloader;
use Tk::FIJITestsViewer;
......@@ -183,17 +183,10 @@ sub _indicate_changes {
}
sub main {
my $logger = get_logger("");
my $name = $0;
my @ARGV = @_;
my $ret = 0;
my $verbosity_delta = 0;
$name =~ s/\.p[lm]//;
my $fiji_version = FIJI_VERSION;
$logger->info("=== Starting new execution of $name $fiji_version ===");
$logger->info(sprintf("%d argument(s)%s", scalar(@_), scalar(@_) > 0 ? ": @_" : ""));
my ($settings_filename, $tests_filename, $help);
......@@ -861,11 +854,8 @@ sub _cleanup {
$worker_tid->join();
}
my $log_conf = File::Spec->catfile($FindBin::Bin, 'logger.conf');
Log::Log4perl::init_and_watch($log_conf, 'HUP');
# We can get the buffered output from the log window
Log::Log4perl->eradicate_appender("string");
exit main(@ARGV);
FIJI::Utils::log_start(1, 0, @ARGV);
exit main();
__END__
......
......@@ -58,16 +58,6 @@ use constant NETLIST_SUFFIX => {
OTHER => 'v',
};
my @argv;
sub log_start {
my $name = basename($0);
$name =~ s/\.p[lm]//;
my $logger = get_logger("");
$logger->info("=== Starting new execution of $name ===");
$logger->info(sprintf("%d argument(s)%s", scalar(@argv), scalar(@argv) > 0 ? ": @argv" : ""));
}
# Filter file line by line and stuff result into $ctx->addfile.
# The filtering happens in a child attached to a pipe to avoid buffering it completely.
sub _crc_filtered {
......@@ -193,7 +183,7 @@ sub main {
$a->filter($ign);
}
$logger->add_appender($custom_file_appender);
log_start();
FIJI::Utils::log_start(0, 0, @ARGV);
foreach my $a (values %{Log::Log4perl->appenders()}) {
$a->{filter} = undef;
}
......@@ -452,16 +442,14 @@ USAGE
return $err;
}
my $log_conf = File::Spec->catfile($FindBin::Bin, 'logger.conf');
Log::Log4perl::init_and_watch($log_conf, 'HUP');
Log::Log4perl->eradicate_appender("string"); # No need for buffered log output
# ARGV gets modified by GetOptions below but we need it later in log_start again
# in case INST_LOG is set to customize the log destination.
my @argv=@ARGV;
FIJI::Utils::log_start(1, 0, @ARGV);
my $logger = get_logger("");
my $break = undef;
# ARGV gets modified by GetOptions below but we need it later in log_start (again)
@argv=@ARGV;
log_start();
# Defaults
my $options = {
......
......@@ -72,14 +72,7 @@ my $rv;
sub main {
my $logger = get_logger("");
my $name = $0;
my @ARGV = @_;
my $verbosity_delta = 0;
$name =~ s/\.p[lm]//;
my $fiji_version = FIJI_VERSION;
$logger->info("=== Starting new execution of $name $fiji_version ===");
$logger->info(sprintf("%d argument(s)%s", scalar(@_), scalar(@_) > 0 ? ": @_" : ""));
my ($settings_filename, $netlist_filename, $help);
my $parse = GetOptions("s|settings=s" => \$settings_filename,
......@@ -684,10 +677,8 @@ sub _cleanup {
$self->{'mw'}->destroy() if $delete_main; # according to Mastering O'Reilly
}
my $log_conf = File::Spec->catfile($FindBin::Bin, 'logger.conf');
Log::Log4perl::init_and_watch($log_conf, 'HUP');
Log::Log4perl->eradicate_appender("string"); # No need for buffered log output
exit main(@ARGV);
FIJI::Utils::log_start(1, 0, @ARGV);
exit main();
__END__
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment