added datetime stamp to prefix
This commit is contained in:
parent
0173d1fe10
commit
fb520c2260
14
logger.cpp
14
logger.cpp
@ -8,6 +8,10 @@
|
||||
|
||||
#include "logger.hpp"
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace sc;
|
||||
|
||||
@ -26,6 +30,16 @@ void logger::msg(loglevel level, const char* file, int line, const char* func) {
|
||||
}
|
||||
|
||||
void logger::write_prefix(loglevel level, const char* file, int line, const char* func) {
|
||||
// retrieve accurate time for milliseconds display
|
||||
struct timeval secs;
|
||||
(void)::gettimeofday(&secs, nullptr);
|
||||
int ms = static_cast<int>(std::roundf(secs.tv_usec / 1000.0)) % 1000;
|
||||
|
||||
// create a date/time stamp
|
||||
char dtstamp[20];
|
||||
std::strftime(dtstamp, 20, "%F %T", std::localtime(&secs.tv_sec));
|
||||
|
||||
std::cerr << dtstamp << "." << std::setw(3) << ms << " ";
|
||||
std::cerr << _name << "[" << ::getpid() << "] ";
|
||||
std::cerr << file << ":" << line << " " << func << "() ";
|
||||
std::cerr << '[' << loglevel_desc(level) << "] ";
|
||||
|
Loading…
x
Reference in New Issue
Block a user