Skip to content

Commit 89d8153

Browse files
committed
Load log settings before all other settings.
Loading the log settings last causes heaps of INFO messages to be displayed by lsl::get_local_interfaces() even if the user has set log level to -3. Changing the order causes less ui clutter and respects the users choices.
1 parent 9ab8541 commit 89d8153

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/api_config.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ void api_config::load_from_file(const std::string &filename) {
9292
}
9393
}
9494

95+
// read the [log] settings
96+
int log_level = pt.get("log.level", (int)loguru::Verbosity_INFO);
97+
if (log_level < -3 || log_level > 9)
98+
throw std::runtime_error("Invalid log.level (valid range: -3 to 9");
99+
100+
std::string log_file = pt.get("log.file", "");
101+
if (!log_file.empty()) {
102+
loguru::add_file(log_file.c_str(), loguru::Append, log_level);
103+
// don't duplicate log to stderr
104+
loguru::g_stderr_verbosity = -9;
105+
} else
106+
loguru::g_stderr_verbosity = log_level;
107+
108+
// log config filename only after setting the verbosity level
109+
if (!filename.empty())
110+
LOG_F(INFO, "Configuration loaded from %s", filename.c_str());
111+
else
112+
LOG_F(INFO, "Loaded default config");
113+
95114
// read out the [ports] parameters
96115
multicast_port_ = pt.get("ports.MulticastPort", 16571);
97116
base_port_ = pt.get("ports.BasePort", 16572);
@@ -250,25 +269,6 @@ void api_config::load_from_file(const std::string &filename) {
250269
smoothing_halftime_ = pt.get("tuning.SmoothingHalftime", 90.0F);
251270
force_default_timestamps_ = pt.get("tuning.ForceDefaultTimestamps", false);
252271

253-
// read the [log] settings
254-
int log_level = pt.get("log.level", (int)loguru::Verbosity_INFO);
255-
if (log_level < -3 || log_level > 9)
256-
throw std::runtime_error("Invalid log.level (valid range: -3 to 9");
257-
258-
std::string log_file = pt.get("log.file", "");
259-
if (!log_file.empty()) {
260-
loguru::add_file(log_file.c_str(), loguru::Append, log_level);
261-
// don't duplicate log to stderr
262-
loguru::g_stderr_verbosity = -9;
263-
} else
264-
loguru::g_stderr_verbosity = log_level;
265-
266-
// log config filename only after setting the verbosity level
267-
if (!filename.empty())
268-
LOG_F(INFO, "Configuration loaded from %s", filename.c_str());
269-
else
270-
LOG_F(INFO, "Loaded default config");
271-
272272
} catch (std::exception &e) {
273273
LOG_F(ERROR, "Error parsing config file '%s': '%s', rolling back to defaults",
274274
filename.c_str(), e.what());

0 commit comments

Comments
 (0)