Commit 133590d1 authored by fmg005's avatar fmg005

added method to log data

parent d0853496
......@@ -5,8 +5,10 @@ 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[0] << "Date"<<setw(12)<<"Time"<<setw(12)<<"Tz"<<setw(3)<<" "<<"Level"<<setw(9)<<"Message"<<endl;
m_logstream[1] <<"start time,"<<"end time,"<<"duration(s),"<<"next_update time"<<endl;
m_logstream[2].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,"<<"end time,"<<"duration(s),"<<"next_update time"<<endl;
m_logstream[2]<<"Time,"<<"Sytolic,"<<"Diatolic,"<<"MAP,"<<"infusion_rate"<<endl;
/* mapping strings to levels */
logging_levels["DEBUG"] = CLA::LOGGER::DEBUG;
logging_levels["INFO"] = CLA::LOGGER::INFO;
......@@ -20,8 +22,10 @@ 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[0] << "Date"<<setw(12)<<"Time"<<setw(12)<<"Tz"<<setw(3)<<" "<<"Level"<<setw(9)<<"Message"<<endl;
m_logstream[1] <<"start time,"<<"end time,"<<"duration(s),"<<"next_update time"<<endl;
m_logstream[2]<<"Time,"<<"Sytolic,"<<"Diatolic,"<<"MAP,"<<"infusion_rate"<<endl;
/* mapping strings to levels */
logging_levels["DEBUG"] = CLA::LOGGER::DEBUG;
logging_levels["INFO"] = CLA::LOGGER::INFO;
......@@ -60,6 +64,13 @@ string CLA::LOGGER::format_chrono_time(time_t t) {
}
string CLA::LOGGER::format_chrono_time(system_clock::time_point t) {
char buff[20];
auto in_time = system_clock::to_time_t(t);
strftime(buff, 20, "%X.", localtime(&in_time));
return buff;
}
string CLA::LOGGER::format_chrono_time_ms(system_clock::time_point t) {
char buff[20];
char m_sec_buff[10];
auto in_time = system_clock::to_time_t(t);
......@@ -71,8 +82,8 @@ string CLA::LOGGER::format_chrono_time(system_clock::time_point t) {
return buff;
}
void CLA::LOGGER::log_duration(system_clock::time_point start_time, system_clock::time_point end_time, time_t duration_time,
time_t next_update_time) {
void CLA::LOGGER::log_duration(system_clock::time_point start_time, system_clock::time_point
end_time, time_t duration_time, time_t next_update_time) {
ss<< format_chrono_time(start_time);
ss<< ",";
ss<< format_chrono_time(end_time);
......@@ -84,6 +95,21 @@ time_t next_update_time) {
ss.str("");
}
void CLA::LOGGER::log_data(system_clock::time_point _time, double systolic, double diastolic,
double MAP, double rate) {
ss<< format_chrono_time(_time);
ss<< ",";
ss<< systolic;
ss<< ",";
ss<< diastolic;
ss<< ",";
ss<<MAP;
ss<<",";
ss<<rate;
m_logstream[2] << ss.str() << endl;
ss.str("");
}
void CLA::LOGGER::setLevel(const string& level) {
/* all `logging levels` less than `level` in severity will be ignored*/
DEFAULT_LEVEL = logging_levels[level];
......@@ -118,7 +144,7 @@ string CLA::LOGGER::convert_level_to_string(LEVEL level) {
}
CLA::LOGGER::~LOGGER() {
for (int i = 0; i < 2; i++) {
for (int i = 0; i < 3; i++) {
m_logstream[i].flush();
m_logstream[i].close();
}
......
......@@ -33,12 +33,14 @@ namespace CLA {
string current_time(bool);
string format_chrono_time(time_t);
string format_chrono_time(system_clock::time_point);
string format_chrono_time_ms(system_clock::time_point);
string convert_level_to_string(LEVEL);
map<std::string, LEVEL> logging_levels;
public:
LOGGER(const string&);
LOGGER(const string&, const string&);
void log_duration(system_clock::time_point, system_clock::time_point, time_t, time_t);
void log_data(system_clock::time_point, double, double, double, double);
~LOGGER();
void setLevel(const string&);
void setVerbosity(bool);
......@@ -80,7 +82,7 @@ namespace CLA {
template <typename T>
void warn(const T& t) {
if (LOGGER::WARN > DEFAULT_LEVEL) {
if (LOGGER::WARN >= DEFAULT_LEVEL) {
ss<< current_time(true);
ss<< setw(2);
ss<< " ";
......
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