Skip to content

Commit

Permalink
Update log level handling
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Oct 22, 2024
1 parent 83d98a8 commit 1d461b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 4 additions & 0 deletions cpp/initiator/initiator_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ bool initiator_util::SetLogLevel(const string &log_level)
// Default spdlog format without the date
set_pattern("[%T.%e] [%^%l%$] %v");

if (log_level.empty()) {
return true;
}

// Compensate for spdlog using 'off' for unknown levels
if (const level::level_enum level = level::from_str(log_level); to_string_view(level) == log_level) {
set_level(level);
Expand Down
15 changes: 5 additions & 10 deletions cpp/s2pexec/s2pexec_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool S2pExec::Init(bool in_process)
return true;
}

bool S2pExec::ParseArguments(span<char*> args, bool in_process)
bool S2pExec::ParseArguments(span<char*> args)
{
const vector<option> options = {
{ "buffer-size", required_argument, nullptr, 'b' },
Expand Down Expand Up @@ -219,13 +219,8 @@ bool S2pExec::ParseArguments(span<char*> args, bool in_process)
return true;
}

// In in-process mode do not change the log level of the target process
if (!in_process && !SetLogLevel(log_level)) {
// Preserve the existing log level for interactive mode
const string &tmp = log_level;
const auto &l = to_string_view(get_level());
log_level = string(l.data(), l.size());
throw parser_exception("Invalid log level: '" + tmp + "'");
if (!SetLogLevel(log_level)) {
throw parser_exception("Invalid log level: '" + log_level + "'");
}

if (!initiator.empty()) {
Expand Down Expand Up @@ -325,7 +320,7 @@ bool S2pExec::RunInteractive(bool in_process)
}

try {
if (!ParseArguments(interactive_args, in_process)) {
if (!ParseArguments(interactive_args)) {
continue;
}
}
Expand All @@ -349,7 +344,7 @@ int S2pExec::Run(span<char*> args, bool in_process)
}

try {
if (!ParseArguments(args, in_process)) {
if (!ParseArguments(args)) {
return -1;
}
else if (version || help) {
Expand Down
4 changes: 2 additions & 2 deletions cpp/s2pexec/s2pexec_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class S2pExec
static void Banner(bool, bool);

bool Init(bool);
bool ParseArguments(span<char*>, bool);
bool ParseArguments(span<char*>);
bool RunInteractive(bool);
int Run();

Expand Down Expand Up @@ -74,7 +74,7 @@ class S2pExec
string command;
string data;

string log_level = "info";
string log_level;

string last_input;

Expand Down

0 comments on commit 1d461b3

Please sign in to comment.