BAN: Print timestamps with d{print,warn,error}ln

This commit is contained in:
Oskari Alaranta 2026-02-11 17:33:59 +02:00
parent a74d99de45
commit b48f099aa2
1 changed files with 21 additions and 0 deletions

View File

@ -8,12 +8,31 @@
#include <BAN/Formatter.h>
#include <stdio.h>
#include <time.h>
#define __debug_putchar [](int c) { putc_unlocked(c, stddbg); }
inline uint64_t _ban_init_start_ms()
{
timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
}
inline uint64_t _ban_start_ms = _ban_init_start_ms();
#define __print_timestamp() \
do { \
timespec ts; \
clock_gettime(CLOCK_MONOTONIC, &ts); \
const auto ms = ts.tv_sec * 1000 + ts.tv_nsec / 1000000 - _ban_start_ms; \
BAN::Formatter::print(__debug_putchar, "[{}.{03}] ", ms / 1000, ms % 1000); \
} while (false)
#define dprintln(...) \
do { \
flockfile(stddbg); \
__print_timestamp(); \
BAN::Formatter::print(__debug_putchar, __VA_ARGS__); \
BAN::Formatter::print(__debug_putchar,"\n"); \
fflush(stddbg); \
@ -24,6 +43,7 @@
do { \
flockfile(stddbg); \
BAN::Formatter::print(__debug_putchar, "\e[33m"); \
__print_timestamp(); \
BAN::Formatter::print(__debug_putchar, __VA_ARGS__); \
BAN::Formatter::print(__debug_putchar, "\e[m\n"); \
fflush(stddbg); \
@ -34,6 +54,7 @@
do { \
flockfile(stddbg); \
BAN::Formatter::print(__debug_putchar, "\e[31m"); \
__print_timestamp(); \
BAN::Formatter::print(__debug_putchar, __VA_ARGS__); \
BAN::Formatter::print(__debug_putchar, "\e[m\n"); \
fflush(stddbg); \