Skip to content

Commit 5a8d315

Browse files
committed
Final Variant never have a log4cpp instance it just logs everything apparently
1 parent 98fcc6d commit 5a8d315

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

projects/biogears/libBiogears/include/biogears/cdm/utils/Logger.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class BIOGEARS_API Logger {
8888
void ResetLogFile(const char* logFilename , const char* working_dir = Loggable::empty_cStr);
8989

9090
void SetLogLevel(log4cpp::Priority::Value priority);
91+
void SetConsoleLogLevel(log4cpp::Priority::Value priority);
9192
log4cpp::Priority::Value GetLogLevel();
9293

9394
virtual void SetLogTime(const SEScalarTime* time);

projects/biogears/libBiogears/src/cdm/engine/PhysiologyEngineDynamicStabilization.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ bool PhysiologyEngineDynamicStabilization::Stabilize(PhysiologyEngine& engine, c
170170
}
171171
//-----------------------------------------------------------------------------
172172
PhysiologyEngineDynamicStabilizer::PhysiologyEngineDynamicStabilizer(double timeStep_s, const PhysiologyEngineDynamicStabilizationCriteria& criteria)
173-
: m_properties(criteria.GetPropertyConvergence())
173+
: Loggable(criteria.GetLogger())
174+
, m_properties(criteria.GetPropertyConvergence())
174175
{
175176
m_dT_s = timeStep_s;
176177
m_totTime_s = 0;
@@ -228,11 +229,11 @@ void PhysiologyEngineDynamicStabilizer::Converge()
228229
if (!m_converged && m_passTime_s >= m_covTime_s) { // We have converged
229230
m_converged = true;
230231
if (m_hasOptionalProperties)
231-
Info("We have passed required convergence criteria, attempting to converge optional properties from multiple conditions.");
232+
Warning("We have passed required convergence criteria, attempting to converge optional properties from multiple conditions.");
232233
}
233234
if (m_converged && m_optsPassTime_s >= m_covTime_s) { // We have converged optional props
234235
m_convergedOptional = true;
235-
Info("We have passed required and optional convergence criteria.");
236+
Warning("We have passed required and optional convergence criteria.");
236237
}
237238

238239
if (m_totTime_s > m_maxTime_s) {

projects/biogears/libBiogears/src/cdm/utils/Logger.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ Logger::Logger(const char* logFilename, const char* working_dir)
4343
void Logger::LogToConsole(bool log_to_console)
4444
{
4545
if (log_to_console) {
46-
m_Log->addAppender(m_ConsoleAppender);
46+
m_Log->addAppender(*m_ConsoleAppender);
4747
} else {
4848
m_Log->removeAppender(m_ConsoleAppender);
4949
}
5050
}
5151

5252
void Logger::ResetLogFile(const std::string& logFilename, const std::string& working_dir)
5353
{
54-
log4cpp::Category& category = log4cpp::Category::getInstance(logFilename);
54+
std::string key = logFilename; if( logFilename.empty()) { key = "biogears_logger"; }
55+
log4cpp::Category& category = log4cpp::Category::getInstance(key);
5556
m_Log = &category;
5657
m_Log->removeAllAppenders();
5758
m_Log->setPriority(log4cpp::Priority::INFO);
@@ -77,10 +78,11 @@ void Logger::ResetLogFile(const std::string& logFilename, const std::string& wor
7778

7879
m_ConsoleAppender = log4cpp::Appender::getAppender(logFilename + "_console");
7980
if (m_ConsoleAppender == nullptr) {
80-
m_ConsoleAppender = new log4cpp::OstreamAppender("console", &std::cout);
81+
m_ConsoleAppender = new log4cpp::OstreamAppender(logFilename + "_console", &std::cout);
8182
log4cpp::PatternLayout* cLayout = new log4cpp::PatternLayout();
8283
cLayout->setConversionPattern("%d [%p] %m%n");
8384
m_ConsoleAppender->setLayout(cLayout);
85+
m_ConsoleAppender->setThreshold(log4cpp::Priority::INFO);
8486
}
8587
LogToConsole(true);
8688
}
@@ -101,8 +103,17 @@ void Logger::SetLogTime(const SEScalarTime* time) { m_time = time; }
101103
// This function will change the priority of the logger
102104
void Logger::SetLogLevel(log4cpp::Priority::Value priority)
103105
{
104-
if (m_Log)
106+
if (m_Log) {
105107
m_Log->setPriority(priority);
108+
}
109+
}
110+
111+
// This function will change the priority of the m_ConsoleAppender
112+
void Logger::SetConsoleLogLevel(log4cpp::Priority::Value priority)
113+
{
114+
if (m_ConsoleAppender) {
115+
m_ConsoleAppender->setThreshold(priority);
116+
}
106117
}
107118

108119
// This function will return the priority of the logger

projects/cmd_bio/src/exec/Driver.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ void Driver::queue_Scenario(Executor exec)
152152
std::string results_file = base_file_name + "Results.csv";
153153

154154
std::unique_ptr<PhysiologyEngine> eng;
155+
Logger console_logger;
155156
Logger file_logger(ex.Computed() + parent_dir + console_file);
156-
157157
try {
158-
file_logger.LogToConsole(false);
158+
file_logger.SetConsoleLogLevel(log4cpp::Priority::WARN);
159159
eng = CreateBioGearsEngine(&file_logger);
160160
} catch (std::exception e) {
161161
std::cout << e.what();
@@ -168,14 +168,14 @@ void Driver::queue_Scenario(Executor exec)
168168

169169
//NOTE:Assuming a Patient File
170170
sce.GetInitialParameters().SetPatientFile(ex.Patient());
171-
std::cout << "Starting Scenario: " + trimed_scenario_path+"\n";
171+
console_logger.Info("Starting Scenario: " + trimed_scenario_path);
172172
try
173173
{
174174
BioGearsScenarioExec bse{*eng};
175175
bse.Execute(sce, ex.Computed() + parent_dir + results_file, nullptr);
176-
std::cout << "Completed Scenario: " + trimed_scenario_path +"\n";
176+
console_logger.Info("Completed Scenario: " + trimed_scenario_path);
177177
} catch (...){
178-
std::cout << "Scenario: " + trimed_scenario_path + " Failed.\n";
178+
console_logger.Info("Scenario: " + trimed_scenario_path + " Failed.");
179179
}
180180
};
181181

0 commit comments

Comments
 (0)