Commit e9084f6a authored by fmg005's avatar fmg005

add timestamp to stdout 'info' log messages

parent f91c70a2
......@@ -8,13 +8,18 @@ CLA::LOGGER::LOGGER(const string& filename): m_filename(move(filename)) {
}
string CLA::LOGGER::current_time(){
string CLA::LOGGER::current_time(bool display_tz){
time_t now = time(0);
struct tm* timeinfo;
char buffer[50];
timeinfo = localtime(&now);
strftime(buffer, 50, "%Y-%M-%d %X-%Z", timeinfo);
if (display_tz)
strftime(buffer, 50, "%Y-%M-%d %X-%Z", timeinfo);
else
strftime(buffer, 50, "%Y-%M-%d %X", timeinfo);
return buffer;
}
......
......@@ -22,7 +22,7 @@ namespace CLA {
ostringstream ss;
enum LEVEL {DEBUG, INFO, WARNING, ERROR, FATAL};
string current_time();
string current_time(bool);
string set_level(LEVEL);
public:
......@@ -32,7 +32,7 @@ namespace CLA {
template <typename T>
void debug(const T& t) {
ss << t;
m_logstream<<current_time()<<","<<set_level(LOGGER::DEBUG)<<","+ss.str()+"\n";
m_logstream<<current_time(true)<<","<<set_level(LOGGER::DEBUG)<<","+ss.str()+"\n";
ss.str("");
ss.clear();
}
......@@ -40,8 +40,8 @@ namespace CLA {
template <typename T>
void info(const T& t) {
ss << t;
m_logstream<<current_time()<<","<<set_level(LOGGER::INFO)<<","+ss.str()+"\n";
cout<<current_time()<<":"<<set_level(LOGGER::INFO)<<":"+ss.str()<<endl;
m_logstream<<current_time(true)<<","<<set_level(LOGGER::INFO)<<","+ss.str()+"\n";
cout<<current_time(false)<<":"<<set_level(LOGGER::INFO)<<":"+ss.str()<<endl;
ss.str("");
ss.clear();
}
......@@ -50,7 +50,7 @@ namespace CLA {
template <typename T>
void warning(const T& t) {
ss << t;
m_logstream<<current_time()<<","<<set_level(LOGGER::WARNING)<<","+ss.str()+"\n";
m_logstream<<current_time(true)<<","<<set_level(LOGGER::WARNING)<<","+ss.str()+"\n";
ss.str("");
ss.clear();
}
......@@ -59,7 +59,7 @@ namespace CLA {
template <typename T>
void error(const T& t) {
ss << t;
m_logstream<<current_time()<<","<<set_level(LOGGER::ERROR)<<","+ss.str()+"\n";
m_logstream<<current_time(true)<<","<<set_level(LOGGER::ERROR)<<","+ss.str()+"\n";
ss.str("");
ss.clear();
}
......@@ -68,7 +68,7 @@ namespace CLA {
template <typename T>
void fatal(const T& t) {
ss << t;
m_logstream<<current_time()<<","<<set_level(LOGGER::FATAL)<<","+ss.str()+"\n";
m_logstream<<current_time(true)<<","<<set_level(LOGGER::FATAL)<<","+ss.str()+"\n";
ss.str("");
ss.clear();
}
......
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