Skip to content

Commit

Permalink
changes to logging
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren committed Nov 15, 2024
1 parent c0c78c7 commit d6f501b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
2 changes: 1 addition & 1 deletion export/examples/Resource/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 1 addition & 8 deletions export/include/fmu4cpp/fmu_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 2 additions & 10 deletions export/include/fmu4cpp/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@ namespace fmu4cpp {

// Logs a message.
template<typename... Args>
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>(args)...);
}

// Logs a message.
template<typename... Args>
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>(args)...);
fmiLogger_(c_, instanceName_.c_str(), s, nullptr, message.c_str(), std::forward<Args>(args)...);
}
}

Expand All @@ -39,7 +32,6 @@ namespace fmu4cpp {

bool debugLogging_{false};
std::string instanceName_;
std::string msgBuf_;
};

}// namespace fmu4cpp
Expand Down
2 changes: 1 addition & 1 deletion src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d6f501b

Please sign in to comment.