Skip to content

Commit 2948fb5

Browse files
pmaanencboulay
authored andcommitted
Log that configuration file was loaded only after it was actually loaded.
1 parent a64f4b8 commit 2948fb5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/api_config.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ 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+
95108
// read out the [ports] parameters
96109
multicast_port_ = pt.get("ports.MulticastPort", 16571);
97110
base_port_ = pt.get("ports.BasePort", 16572);
@@ -250,20 +263,7 @@ void api_config::load_from_file(const std::string &filename) {
250263
smoothing_halftime_ = pt.get("tuning.SmoothingHalftime", 90.0F);
251264
force_default_timestamps_ = pt.get("tuning.ForceDefaultTimestamps", false);
252265

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
266+
// log config filename only after setting the verbosity level and all config has been read
267267
if (!filename.empty())
268268
LOG_F(INFO, "Configuration loaded from %s", filename.c_str());
269269
else

0 commit comments

Comments
 (0)