|
|
|
@ -3,6 +3,8 @@ |
|
|
|
#include <chrono> |
|
|
|
#include <chrono> |
|
|
|
|
|
|
|
|
|
|
|
#include "dumbLog.h" |
|
|
|
#include "dumbLog.h" |
|
|
|
|
|
|
|
#include "types.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void dumbLog::setOutputStream(std::ostream* out) |
|
|
|
void dumbLog::setOutputStream(std::ostream* out) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -33,7 +35,36 @@ int |
|
|
|
dumbLog::getCurrentMS() |
|
|
|
dumbLog::getCurrentMS() |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto now = std::chrono::system_clock::now(); |
|
|
|
auto now = std::chrono::system_clock::now(); |
|
|
|
long long total_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count(); |
|
|
|
u64 total_ms = std::chrono::duration_cast<std::chrono::milliseconds>( |
|
|
|
|
|
|
|
now.time_since_epoch() |
|
|
|
|
|
|
|
).count(); |
|
|
|
return int(total_ms % 1000); |
|
|
|
return int(total_ms % 1000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <cstdarg> |
|
|
|
|
|
|
|
#include <ctime> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
|
|
|
dumbLogF(log_level l, const char* func, const char* fmt, ...) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const char* level = logger.logLevelToString(l); |
|
|
|
|
|
|
|
char time_str[100]; |
|
|
|
|
|
|
|
timespec ts; |
|
|
|
|
|
|
|
timespec_get(&ts, TIME_UTC); |
|
|
|
|
|
|
|
i64 ms = ts.tv_nsec / 1000000; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strftime(time_str, sizeof(time_str), "%T", localtime(&ts.tv_sec))) { |
|
|
|
|
|
|
|
// NOTE: print prefix, "H:M:S.ms, log_level, function(), "
|
|
|
|
|
|
|
|
printf("%s.%03ld [%s] %s(), ", time_str, ms, level, func); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: append user args
|
|
|
|
|
|
|
|
va_list args; |
|
|
|
|
|
|
|
va_start(args, fmt); |
|
|
|
|
|
|
|
vprintf(fmt, args); |
|
|
|
|
|
|
|
va_end(args); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
printf("%s(), error getting time\n", __FUNCTION__); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|