Commit e2feea6f authored by Stefan Tauner's avatar Stefan Tauner
Browse files

FIJITestsViewer: reduce verbosity of messages in the live log

 - add a new pattern to the logger.conf file (and a fallback
   one hardcoded to FIJITestsViewer)
 - parse the config file within FIJITestsViewer and change the layout
   pattern of the QueueAppender accordingly
 - make sure the download worker uses the same logger configuration
   as the main thread by re-applying the same changes in the worker thread
 - also, add indentation to ordinary multi-line log messages
parent 81226f33
......@@ -526,21 +526,11 @@ sub _populate_widget {
$self->{'logbox'}->tagConfigure($k, -font => LOG4P_FONTS->{$k});
}
# the log textbox needs to be updated periodically
# _update_logging_box will try to read from the logging queue
my $logupdater = $self->repeat(100, [\&_update_logging_box, $self]);
# Append any messages from the logging queue to textbox periodically
$self->repeat(100, [\&_update_logging_box, $self]);
# also log to the log_queue
my $file_appender = $Log::Log4perl::Logger::APPENDER_BY_NAME{'screen'};
my $custom_appender = Log::Log4perl::Appender->new(
"Log::Dispatch::QueueAppender",
name => "queueAppender",
threshold => "info",
queue => $self->{'log_queue'},
);
my $layout = $file_appender->{'layout'};
$custom_appender->layout(clone($layout));
$logger->add_appender($custom_appender);
append_logger($self->{'log_queue'});
$logger->info("Live capturing of log output has started");
#---
......@@ -1171,4 +1161,29 @@ sub _check_change {
}
}
sub append_logger {
my $logger = get_logger("");
my $custom_appender = Log::Log4perl::Appender->new(
"Log::Dispatch::QueueAppender",
name => "queueAppender",
threshold => "info",
queue => shift,
);
my $conf = Log::Log4perl::Config::PropertyConfigurator->new();
my $logger_conf = Log::Log4perl::Config::watcher()->file();
$conf->file($logger_conf);
eval{$conf->parse()}; # would die() on error
my $layout_pattern_short;
if ($@) {
$layout_pattern_short = "%d{HH:mm:ss.SSS} %p - %m%n";
$logger->error("Could not parse $logger_conf to get shortened pattern for live logging)\n".
"Using \"$layout_pattern_short\" instead.");
} else {
$layout_pattern_short = $conf->value("layout_pattern_short");
}
my $layout = Log::Log4perl::Layout::PatternLayout->new($layout_pattern_short);
$custom_appender->layout($layout);
$logger->add_appender($custom_appender);
}
1;
......@@ -98,24 +98,19 @@ END_USAGE
# Logging is done via a Queue so the Tk Part can display log messages in a
# Tk widget.
sub download_worker {
my $logger = get_logger("");
eval {
my $cont = 1;
$SIG{'STOP'} = sub { $cont = 0; };
my $logger = get_logger("");
my $file_appender = $Log::Log4perl::Logger::APPENDER_BY_NAME{'screen'};
my $custom_appender = Log::Log4perl::Appender->new(
"Log::Dispatch::QueueAppender",
name => "queueAppender",
threshold => "info",
queue => $log_queue,
);
my $layout = $file_appender->{'layout'};
$custom_appender->layout(clone($layout));
$logger->add_appender($custom_appender);
$queue_to_gui->enqueue({state => "starting"});
# We need to re-append the log queue to the logger here because
# the GUI does it after this thread is created and hence the
# logger object of this thread does not get updated.
# Perl threads don't share variables...
Tk::FIJITestsViewer::append_logger($log_queue);
# forever, get new workload
while (defined(my $item = $queue_to_worker->dequeue())) {
my $dl = $item->{'downloader'};
......@@ -159,7 +154,6 @@ sub download_worker {
}
};
if ($@ ne "") {
my $logger = get_logger("");
$logger->error("Download worker exited unexpectedly: $@");
# Return only first line of what eval returns to the GUI.
# Usually this is something like:
......@@ -211,6 +205,9 @@ sub main {
return 0;
}
# Create heavy thread as soon as possible
$worker_tid = threads->create('download_worker');
my %hash;
my $self = bless(\%hash);
......@@ -222,8 +219,6 @@ sub main {
my $settings_ini_name;
$self->{'settings_ini_name'} = \$settings_ini_name;
$worker_tid = threads->create('download_worker');
#
# Build GUI
#
......
layout_class = Log::Log4perl::Layout::PatternLayout
# layout_class = Log::Log4perl::Layout::SimpleLayout
layout_pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %p - %m (%F:%L> %M)%n
layout_pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %p - %m{indent} (%F:%L> %M)%n
layout_pattern_short = %d{HH:mm:ss.SSS} %p - %m{indent}%n
log4perl.rootLogger = TRACE, logfile, screen
......
Supports Markdown
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