Skip to content

Commit

Permalink
Initialize logging early.
Browse files Browse the repository at this point in the history
So it is available when parsing other options too.
  • Loading branch information
kraiskil committed Aug 9, 2023
1 parent 94eda90 commit e438c19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
12 changes: 0 additions & 12 deletions src/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ Graph::Graph(
:model(onnx_model)
{

AixLog::Severity s;
switch(options.logging_level)
{
case 4: s = AixLog::Severity::trace; break;
case 3: s = AixLog::Severity::debug; break;
default:
case 2: s = AixLog::Severity::info; break;
case 1: s = AixLog::Severity::warning; break;
case 0: s = AixLog::Severity::error; break;
}
AixLog::Log::init<AixLog::SinkCerr>(s);

processGraph(onnx_model, ext_inputs);
}

Expand Down
20 changes: 19 additions & 1 deletion src/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ void print_version_and_exit(void)
exit(0);
}

void initialize_logging(void)
{
AixLog::Severity s;
switch(options.logging_level)
{
case 4: s = AixLog::Severity::trace; break;
case 3: s = AixLog::Severity::debug; break;
default:
case 2: s = AixLog::Severity::info; break;
case 1: s = AixLog::Severity::warning; break;
case 0: s = AixLog::Severity::error; break;
}
AixLog::Log::init<AixLog::SinkCerr>(s);
}

void store_define_option(const std::string &opt)
{
auto delim_pos = opt.find(':', 0 );
Expand Down Expand Up @@ -82,6 +97,10 @@ void parse_cmdline_options(int argc, const char *argv[])

if (help) { std::cout << parser; exit(0); }
if (version) { print_version_and_exit(); }
if (loglevel) {options.logging_level = args::get(loglevel); }

// initialize logging as soon as possible, so logging is available in parsing the options too
initialize_logging();

if (quantize) { options.quantize = true; }
if (avr) { options.target_avr = true; }
Expand All @@ -91,7 +110,6 @@ void parse_cmdline_options(int argc, const char *argv[])
}
}
if (input) { options.input_file = args::get(input); }
if (loglevel) {options.logging_level = args::get(loglevel); }
if (options.input_file == "" ) { std::cerr << "No input file given"; hint_at_help_and_exit(); }
}

0 comments on commit e438c19

Please sign in to comment.