Skip to content

Commit

Permalink
Use correct field name for log level override by command line in json
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Oct 24, 2023
1 parent a3563d0 commit 906e66a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/engine/src/coincenterinfo_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@
namespace cct {

namespace {

json LoadGeneralConfigAndOverrideOptionsFromCLI(const CoincenterCmdLineOptions &cmdLineOptions) {
json generalConfigData = GeneralConfig::LoadFile(cmdLineOptions.dataDir);

// Override general config options from CLI
// Use at method to make sure to throw if key is not already present (it should)
if (!cmdLineOptions.apiOutputType.empty()) {
generalConfigData["apiOutputType"] = cmdLineOptions.apiOutputType;
generalConfigData.at("apiOutputType") = cmdLineOptions.apiOutputType;
}
if (!cmdLineOptions.logConsole.empty()) {
generalConfigData["log"]["console"] = string(cmdLineOptions.logConsole);
generalConfigData.at("log").at(LoggingInfo::kJsonFieldConsoleLevelName) = string(cmdLineOptions.logConsole);
}
if (!cmdLineOptions.logFile.empty()) {
generalConfigData["log"]["file"] = string(cmdLineOptions.logFile);
generalConfigData.at("log").at(LoggingInfo::kJsonFieldFileLevelName) = string(cmdLineOptions.logFile);
}

return generalConfigData;
Expand Down
4 changes: 3 additions & 1 deletion src/objects/include/logginginfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class LoggingInfo {
static constexpr int64_t kDefaultFileSizeInBytes = 5L * 1024 * 1024;
static constexpr int32_t kDefaultNbMaxFiles = 10;
static constexpr char const *const kOutputLoggerName = "output";
static constexpr std::string_view kJsonFieldConsoleLevelName = "consoleLevel";
static constexpr std::string_view kJsonFieldFileLevelName = "fileLevel";

enum class WithLoggersCreation : int8_t { kNo, kYes };

Expand All @@ -31,7 +33,7 @@ class LoggingInfo {
LoggingInfo(const LoggingInfo &) = delete;
LoggingInfo(LoggingInfo &&loggingInfo) noexcept;
LoggingInfo &operator=(const LoggingInfo &) = delete;
LoggingInfo &operator=(LoggingInfo &&loggingInfo) = delete;
LoggingInfo &operator=(LoggingInfo &&) = delete;

~LoggingInfo();

Expand Down
6 changes: 4 additions & 2 deletions src/objects/src/logginginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ LoggingInfo::LoggingInfo(WithLoggersCreation withLoggersCreation, std::string_vi
: _dataDir(dataDir),
_maxFileSizeLogFileInBytes(ParseNumberOfBytes(generalConfigJsonLogPart["maxFileSize"].get<std::string_view>())),
_maxNbLogFiles(generalConfigJsonLogPart["maxNbFiles"].get<int>()),
_logLevelConsolePos(LogPosFromLogStr(generalConfigJsonLogPart["consoleLevel"].get<std::string_view>())),
_logLevelFilePos(LogPosFromLogStr(generalConfigJsonLogPart["fileLevel"].get<std::string_view>())) {
_logLevelConsolePos(
LogPosFromLogStr(generalConfigJsonLogPart[LoggingInfo::kJsonFieldConsoleLevelName].get<std::string_view>())),
_logLevelFilePos(
LogPosFromLogStr(generalConfigJsonLogPart[LoggingInfo::kJsonFieldFileLevelName].get<std::string_view>())) {
if (withLoggersCreation == WithLoggersCreation::kYes) {
createLoggers();
}
Expand Down

0 comments on commit 906e66a

Please sign in to comment.