From d6f501b50c160c217f4cf72e5ea029b688e34bda Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Fri, 15 Nov 2024 13:11:50 +0100 Subject: [PATCH] changes to logging --- export/examples/Resource/resource.cpp | 2 +- export/include/fmu4cpp/fmu_base.hpp | 9 +-------- export/include/fmu4cpp/logger.hpp | 12 ++---------- src/model.cpp | 2 +- 4 files changed, 5 insertions(+), 20 deletions(-) diff --git a/export/examples/Resource/resource.cpp b/export/examples/Resource/resource.cpp index e378a8f..35f6604 100644 --- a/export/examples/Resource/resource.cpp +++ b/export/examples/Resource/resource.cpp @@ -29,7 +29,7 @@ class Resource : public fmu_base { bool do_step(double currentTime, double dt) override { - debugLog(fmi2OK, get_string_variable("content")->get()); + log(fmi2OK, get_string_variable("content")->get()); return true; } diff --git a/export/include/fmu4cpp/fmu_base.hpp b/export/include/fmu4cpp/fmu_base.hpp index 85ccd61..9d16ee6 100644 --- a/export/include/fmu4cpp/fmu_base.hpp +++ b/export/include/fmu4cpp/fmu_base.hpp @@ -141,19 +141,12 @@ namespace fmu4cpp { logger_ = logger; } - void log(fmi2Status s, const std::string &message) { + void log(const fmi2Status s, const std::string &message) { if (logger_) { logger_->log(s, message); } } - void debugLog(fmi2Status s, const std::string &message) { - if (logger_) { - logger_->debug(s, message); - } - } - - virtual void *getFMUState() { return nullptr; diff --git a/export/include/fmu4cpp/logger.hpp b/export/include/fmu4cpp/logger.hpp index 3e45288..4b8decc 100644 --- a/export/include/fmu4cpp/logger.hpp +++ b/export/include/fmu4cpp/logger.hpp @@ -20,16 +20,9 @@ namespace fmu4cpp { // Logs a message. template - void log(fmi2Status s, const std::string &message, Args &&...args) { - msgBuf_ = message; - fmiLogger_(c_, instanceName_.c_str(), s, nullptr, msgBuf_.c_str(), std::forward(args)...); - } - - // Logs a message. - template - void debug(fmi2Status s, const std::string &message, Args &&...args) { + void log(const fmi2Status s, const std::string &message, Args &&...args) { if (debugLogging_) { - log(s, message, std::forward(args)...); + fmiLogger_(c_, instanceName_.c_str(), s, nullptr, message.c_str(), std::forward(args)...); } } @@ -39,7 +32,6 @@ namespace fmu4cpp { bool debugLogging_{false}; std::string instanceName_; - std::string msgBuf_; }; }// namespace fmu4cpp diff --git a/src/model.cpp b/src/model.cpp index f0069f7..63cede4 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -69,7 +69,7 @@ class Model : public fmu_base { } bool do_step(double currentTime, double dt) override { - debugLog(fmi2OK, "hello@ " + std::to_string(currentTime)); + log(fmi2OK, "hello@ " + std::to_string(currentTime)); return true; }