emilk / loguru

A lightweight C++ logging library
The Unlicense
1.77k stars 256 forks source link

Request: on Linux, option to use system uptime instead of program uptime #164

Open cxw42 opened 3 years ago

cxw42 commented 3 years ago

In my use case at $work, I need to correlate loguru logs from a userspace program with dmesg output. Unfortunately, this is an old enough system that it does not support dmesg -T :(. Therefore, it would be very helpful for the loguru "uptime" field to have an option to use the system uptime. That can be had using clock_gettime():

#include <stdio.h>
#include <time.h>

int main()
{
    struct timespec ts;
    clock_gettime(CLOCK_BOOTTIME, &ts);
    printf("%f\n", ts.tv_sec + (double)ts.tv_nsec/1e9);
    return 0;
}

Would you be willing to add this as a compile-time or run-time option? Thank you for considering this request!

emilk commented 3 years ago

Loguru is in passive maintenance mode. If you make a PR for it with some docs and everything is green, I will merge it! Make sure it compiles on all platforms (it's fine if the flag only exists on some platforms).