loguru
loguru copied to clipboard
Custom YYYY field
It will be awesome if the 1900 + time_info.tm_year column can be hidden (via a customization option)
void write_date_time(char* buff, size_t buff_size)
{
auto now = system_clock::now();
long long ms_since_epoch = duration_cast<milliseconds>(now.time_since_epoch()).count();
time_t sec_since_epoch = time_t(ms_since_epoch / 1000);
tm time_info;
localtime_r(&sec_since_epoch, &time_info);
snprintf(buff, buff_size, "%04d%02d%02d_%02d%02d%02d.%03lld",
1900 + time_info.tm_year, 1 + time_info.tm_mon, time_info.tm_mday,
time_info.tm_hour, time_info.tm_min, time_info.tm_sec, ms_since_epoch % 1000);
}
@jacobdufault
char buff[256];
loguru::write_data_time(buff, sizeof(buff));
const char* date_time_without_year = buff + 4;
printf("%s", date_time_without_year);
?
Does https://github.com/emilk/loguru/pull/52/files help ?
There is now loguru::g_preamble_date which allows you to hide the whole date:
int main(int argc, char* argv[])
{
loguru::g_preamble_date = false;
loguru::init(argc, argv);
}
is this good enough? Or do you want to be able to hide the year specifically?