Commit 7a64d795 authored by Christian Fibich's avatar Christian Fibich Committed by Stefan Tauner
Browse files

-v verbosity command line parameter

parent e19e1bda
package FIJI::Utils;
use Log::Log4perl qw(get_logger);
use Log::Log4perl::Level;
use Cwd 'realpath';
use if $^O eq "MSWin32", "Win32::TieRegistry";
sub set_verbosity {
my $verbosity = shift;
my $logger = get_logger("");
my $screen_appender = $Log::Log4perl::Logger::APPENDER_BY_NAME{'screen'};
my $old_log_level = $screen_appender->threshold();
my $new_log_level = $old_log_level;
if ($verbosity > 0) {
$new_log_level = $screen_appender->threshold(Log::Log4perl::Level::get_lower_level($old_log_level,$verbosity));
$logger->trace("Verbosity: $verbosity. Decrease Screen log threshold from ", Log::Log4perl::Level::to_level( $old_log_level ), " to ", Log::Log4perl::Level::to_level( $new_log_level ));
}
return $new_log_level;
}
sub system {
my $logger = get_logger("");
my @cli = @_;
......
......@@ -27,6 +27,7 @@ use warnings;
our $VERSION = '0.1';
use Log::Dispatch::Output;
use Log::Log4perl::Level;
use base qw( Log::Dispatch::Output );
use threads;
......@@ -51,7 +52,7 @@ sub new {
my $self = bless \%p, $class;
$self->_basic_init(%p);
$self->{'min_level'} = $self->{'level_numbers'}->{$p{threshold}} if defined $self->{'level_numbers'}->{$p{threshold}};
$self->{'min_level'} = $p{threshold};
return $self;
}
......
......@@ -116,6 +116,7 @@ sub Populate {
$self->{'queue_to_worker'} = delete $args->{'-queue_to_worker'};
$self->{'queue_from_worker'} = delete $args->{'-queue_from_worker'};
$self->{'log_queue'} = delete $args->{'-log_queue'};
$self->{'loglevel'} = delete $args->{'-loglevel'};
if (!defined($settings) || !blessed($settings) || !$settings->isa("FIJI::Settings")) {
$logger->error("No or invalid settings given.");
......@@ -529,7 +530,7 @@ sub _populate_widget {
$self->repeat(100, [\&_update_logging_box, $self]);
# also log to the log_queue
append_logger($self->{'log_queue'});
append_logger($self->{'log_queue'},$self->{'loglevel'});
$logger->info("Live capturing of log output has started");
#---
......@@ -1207,12 +1208,16 @@ sub _check_change {
sub append_logger {
my $logger = get_logger("");
my ($queue, $log4plevel) = @_;
my $threshold = $Log::Log4perl::Level::L4P_TO_LD{Log::Log4perl::Level::to_level($log4plevel)};
my $custom_appender = Log::Log4perl::Appender->new(
"Log::Dispatch::QueueAppender",
name => "queueAppender",
threshold => "info",
queue => shift,
threshold => lc($threshold),
queue => $queue,
);
my $conf = Log::Log4perl::Config::PropertyConfigurator->new();
my $logger_conf = Log::Log4perl::Config::watcher()->file();
$conf->file($logger_conf);
......@@ -1227,6 +1232,7 @@ sub append_logger {
}
my $layout = Log::Log4perl::Layout::PatternLayout->new($layout_pattern_short);
$custom_appender->layout($layout);
$custom_appender->threshold($log4plevel);
$logger->add_appender($custom_appender);
}
......
......@@ -28,6 +28,7 @@ use lib "$FindBin::Bin";
use Log::Log4perl qw(get_logger);
use FIJI::Downloader;
use FIJI::Utils;
use File::Basename;
use Data::Dumper;
use Getopt::Long qw(:config no_ignore_case);
......@@ -178,10 +179,12 @@ GetOptions(
"d|prob-dly=f" => \($prob->{'PROB_DELAY'}),
"f|prob-seu=f" => \($prob->{'PROB_SEU'}),
"o|prob-so=f" => \($prob->{'PROB_STUCK_OPEN'}),
"verbose+" => \($cfg->{'verbose'}),
"help" => \($cfg->{'help'}),
)
or print STDERR $USAGE and die("Invalid arguments");
my $log_conf = File::Spec->catfile($FindBin::Bin, 'logger.conf');
Log::Log4perl::init_and_watch($log_conf, 'HUP');
FIJI::Utils::set_verbosity($cfg->{'verbose'});
exit main($cfg,$prob,$dur);
......@@ -101,6 +101,7 @@ END_USAGE
# Tk widget.
sub download_worker {
my $logger = get_logger("");
my $loglevel = shift;
eval {
my $cont = 1;
$SIG{'STOP'} = sub { $cont = 0; };
......@@ -111,7 +112,7 @@ sub download_worker {
# 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);
Tk::FIJITestsViewer::append_logger($log_queue,$loglevel);
# forever, get new workload
while (defined(my $item = $queue_to_worker->dequeue())) {
......@@ -193,7 +194,8 @@ sub main {
my $logger = get_logger("");
my $name = $0;
my @ARGV = @_;
my $ret = 0;
my $ret = 0;
my $verbose = 0;
$name =~ s/\.p[lm]//;
$logger->debug("=== Starting new execution of $name ===");
$logger->debug(sprintf("%d argument(s)%s", scalar(@_), scalar(@_) > 0 ? ": @_" : ""));
......@@ -202,8 +204,11 @@ sub main {
my $parse = GetOptions("settings-file=s" => \$settings_filename,
"tests-file=s" => \$tests_filename,
"verbose+" => \$verbose,
"help" => \$help);
my $loglevel = FIJI::Utils::set_verbosity($verbose);
if (!$parse) {
print STDERR $usage;
return -1;
......@@ -214,7 +219,7 @@ sub main {
}
# Create heavy thread as soon as possible
$worker_tid = threads->create('download_worker');
$worker_tid = threads->create('download_worker',$loglevel);
my %hash;
my $self = bless(\%hash);
......@@ -316,6 +321,7 @@ sub main {
-queue_to_worker => $queue_to_worker,
-queue_from_worker => $queue_to_gui,
-log_queue => $log_queue,
-loglevel => $loglevel
);
# Needs to happen after instatiation of FIJITestsViewer due to uart_complete
......
......@@ -41,6 +41,8 @@ use FIJI::Netlist;
use FIJI::VHDL;
use FIJI::Constraints;
use FIJI::Utils;
use File::Spec;
use File::Path qw(make_path);
......@@ -460,6 +462,7 @@ my $options = {
fiji_settings_file => undef,
netlist_file => undef,
file_prefix => undef,
verbose => 0,
output_dir => undef
};
......@@ -468,6 +471,7 @@ GetOptions(
"netlist-file|n=s" => \$options->{'netlist_file'},
"file-prefix|p=s" => \$options->{'file_prefix'},
"output-dir|o=s" => \$options->{'output_dir'},
"verbose+" => \$options->{'verbose'},
"help|h" => sub { exit(usage(0)); },
);
......@@ -490,4 +494,6 @@ $options->{'fiji_settings_file'} = File::Spec->canonpath($options->{'fiji_settin
$options->{'netlist_file'} = File::Spec->canonpath($options->{'netlist_file'});
$options->{'output_dir'} = File::Spec->canonpath($options->{'output_dir'}) if defined $options->{'output_dir'};
FIJI::Utils::set_verbosity($options->{'verbose'});
exit main($options);
......@@ -80,6 +80,7 @@ sub main {
my $logger = get_logger("");
my $name = $0;
my @ARGV = @_;
my $verbose = 0;
$name =~ s/\.p[lm]//;
$logger->debug("=== Starting new execution of $name ===");
$logger->debug(sprintf("%d argument(s)%s", scalar(@_), scalar(@_) > 0 ? ": @_" : ""));
......@@ -88,8 +89,11 @@ sub main {
my $parse = GetOptions("settings-file=s" => \$settings_filename,
"netlist-file=s" => \$netlist_filename,
"verbose+" => \$verbose,
"help" => \$help);
FIJI::Utils::set_verbosity($verbose);
my $only_load = (defined $ENV{FIJI_BENCHMARK} && $ENV{FIJI_BENCHMARK} eq "ONLY_LOAD");
$logger->warn("Benchmarking mode: Terminating after loading settings and netlist") if $only_load;
......
......@@ -19,6 +19,11 @@ following \emph{optional} command-line arguments:
\item \texttt{-n, {-}{-}netlist-file=<filename>}
Specifies a netlist file to load at startup
\item \texttt{-v, {-}{-}verbose}
Increase verbosity on the terminal. Each occurence of \texttt{-v} or
\texttt{{-}{-}verbose} further increases verbosity.
\item \texttt{-h, {-}{-}help}
......
......@@ -48,6 +48,11 @@ the following parameters and switches:
If the specified directory does not exist, it will be created.
This parameter is \emph{optional}.
\item \texttt{-v, {-}{-}verbose}
Increase verbosity on the terminal. Each occurence of \texttt{-v} or
\texttt{{-}{-}verbose} further increases verbosity.
\item \texttt{-h, --help}
Displays usage information on the terminal and exits
......
......@@ -48,6 +48,11 @@ The script also accepts the following \emph{optional} command-line arguments:
The serial port to use. Defaults to the value configured in the \textit{\ac{FIJI} Settings} file
\item \texttt{-v, {-}{-}verbose}
Increase verbosity on the terminal. Each occurence of \texttt{-v} or
\texttt{{-}{-}verbose} further increases verbosity.
\item \texttt{-h, {-}{-}help}
Displays usage information on the terminal and exits
......@@ -178,6 +183,11 @@ following \emph{optional} command-line arguments:
Specifies a \textit{\ac{FIJI} Tests} file to load at startup
\item \texttt{-v, {-}{-}verbose}
Increase verbosity on the terminal. Each occurence of \texttt{-v} or
\texttt{{-}{-}verbose} further increases verbosity.
\item \texttt{-h, {-}{-}help}
Displays usage information on the terminal and exits
......@@ -271,7 +281,7 @@ checkbox.
\begin{figure}[ht]
\centering
\includegraphics[width=0.85\linewidth]{img/fiji_download_manual_screenshot.png}
\includegraphics[width=0.85\linewidth]{img/fiji_ee_manual_screenshot.png}
\caption{\ac{FIJIEE} GUI: Manual Mode}
\label{fig:manual_download_gui}
\end{figure}
......@@ -296,7 +306,7 @@ are configurable:
\begin{figure}[ht]
\centering
\includegraphics[width=0.85\linewidth]{img/fiji_download_random_screenshot.png}
\includegraphics[width=0.85\linewidth]{img/fiji_ee_random_screenshot.png}
\caption{\ac{FIJIEE} GUI: Random Mode}
\label{fig:random_download_gui}
\end{figure}
......
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