Commit 7e532155 authored by fmg005's avatar fmg005

added an overload log_duration method

parent 19273c48
......@@ -5,12 +5,16 @@ CLA::LOGGER::LOGGER(const string& name): m_patient_name(move(name)){
/* timestamped logs */
m_logstream[0].open(prosim_logs_dir+"prosim_"+m_patient_name+current_time(false)+".log");
m_logstream[1].open(prosim_results_dir+"duration_"+m_patient_name+current_time(false)+".txt");
m_logstream[2].open(prosim_results_dir+"data_"+m_patient_name+current_time(false)+".txt");
m_logstream[2].open(prosim_results_dir+"duration_sim_monitor_"\
+m_patient_name+current_time(false)+".txt");
m_logstream[3].open(prosim_results_dir+"data_"+m_patient_name+current_time(false)+".txt");
m_logstream[0]<< "Date"<<setw(12)<<"Time"<<setw(12)<<"Tz"<<setw(3)<<" "\
<<"Level"<<setw(9)<<"Message"<<endl;
m_logstream[1]<<"start time,"<<"engine adv duration(s),"<<"command duration(s),"\
<<"infusion duration(s),"<<"totals duration(s),"<<"next_update time"<<endl;
m_logstream[2]<<" Engine Time,"<<"bpdrug rate,"<<"saline rate"<<endl;
m_logstream[2]<<"start time,"<<"engine adv duration(s),"<<"infusion duration(s),"\
<<"totals duration(s),"<<"next_update time"<<endl;
m_logstream[3]<<" Engine Time,"<<"bpdrug rate,"<<"saline rate"<<endl;
/* mapping strings to levels */
logging_levels["DEBUG"] = CLA::LOGGER::DEBUG;
logging_levels["INFO"] = CLA::LOGGER::INFO;
......@@ -24,12 +28,16 @@ CLA::LOGGER::LOGGER(const string& filename, const string& name): m_filename(move
m_patient_name(move(name)) {
m_logstream[0].open(prosim_logs_dir+m_filename+".log", ios::out|ios::binary);
m_logstream[1].open(prosim_results_dir+"duration_"+m_filename+".txt", ios::out|ios::binary);
m_logstream[2].open(prosim_results_dir+"data_"+m_filename+".txt", ios::out|ios::binary);
m_logstream[2].open(prosim_results_dir+"duration_sim_monitor_"+\
m_filename+".txt", ios::out|ios::binary);
m_logstream[3].open(prosim_results_dir+"data_"+m_filename+".txt", ios::out|ios::binary);
m_logstream[0] << "Date"<<setw(12)<<"Time"<<setw(12)<<"Tz"<<setw(3)<<" "\
<<"Level"<<setw(9)<<"Message"<<endl;
m_logstream[1]<<"start time,"<<"engine adv duration(s),"<<"command duration(s),"\
<<"infusion duration(s),"<<"totals duration(s),"<<"next_update time"<<endl;
m_logstream[2]<<"Engine Time,"<<"bpdrug rate,"<<"saline rate"<<endl;
m_logstream[2]<<"start time,"<<"engine adv duration(s),"<<"infusion duration(s),"\
<<"totals duration(s),"<<"next_update time"<<endl;
m_logstream[3]<<"Engine Time,"<<"bpdrug rate,"<<"saline rate"<<endl;
/* mapping strings to levels */
logging_levels["DEBUG"] = CLA::LOGGER::DEBUG;
logging_levels["INFO"] = CLA::LOGGER::INFO;
......@@ -92,9 +100,9 @@ string CLA::LOGGER::format_chrono_time_ms(system_clock::time_point t) {
return buff;
}
void CLA::LOGGER::log_duration(system_clock::time_point start_time, time_t engine_duration,
time_t command_duration, time_t infusion_duration,time_t total_duration, time_t \
next_update_time) {
void CLA::LOGGER::log_duration(system_clock::time_point start_time, \
time_t engine_duration, time_t command_duration, time_t infusion_duration, \
time_t total_duration, time_t next_update_time) {
ss<< format_chrono_time(start_time);
ss<< ",";
ss<< format_duration(engine_duration);
......@@ -110,6 +118,22 @@ next_update_time) {
ss.str("");
}
void CLA::LOGGER::log_duration(system_clock::time_point start_time, \
time_t engine_duration, time_t infusion_duration,time_t total_duration, \
time_t next_update_time) {
ss<< format_chrono_time(start_time);
ss<< ",";
ss<< format_duration(engine_duration);
ss<< ",";
ss<<format_duration(infusion_duration);
ss<< ",";
ss<<format_duration(total_duration);
ss<< ",";
ss<<format_chrono_time(next_update_time);
m_logstream[2] << ss.str() << endl;
ss.str("");
}
void CLA::LOGGER::log_data(double engine_time, double bpdrug_rate, double \
saline_rate) {
ss<< engine_time;
......@@ -117,7 +141,7 @@ void CLA::LOGGER::log_data(double engine_time, double bpdrug_rate, double \
ss<<bpdrug_rate;
ss<<",";
ss<<saline_rate;
m_logstream[2] << ss.str() << endl;
m_logstream[3] << ss.str() << endl;
ss.str("");
}
......@@ -155,7 +179,7 @@ string CLA::LOGGER::convert_level_to_string(LEVEL level) {
}
CLA::LOGGER::~LOGGER() {
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 4; i++) {
m_logstream[i].flush();
m_logstream[i].close();
}
......
......@@ -25,7 +25,7 @@ namespace CLA {
string level_name;
const string m_filename;
const string m_patient_name;
ofstream m_logstream[3];
ofstream m_logstream[4];
ostringstream ss;
bool m_verbosity = true;
enum LEVEL {DEBUG, INFO, WARN, ERROR, FATAL, NONE};
......@@ -38,11 +38,13 @@ namespace CLA {
string format_duration(time_t);
map<std::string, LEVEL> logging_levels;
public:
LOGGER(const string&);
LOGGER(const string&, const string&);
LOGGER(const string&); // filename
LOGGER(const string&, const string&); // filename, patient_name
~LOGGER();
void log_duration(system_clock::time_point, time_t, time_t, time_t, \
time_t, time_t);
void log_duration(system_clock::time_point, time_t, time_t, time_t, \
time_t);
void log_data(double, double, double);
void setLevel(const string&);
void setVerbosity(bool);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment