diff --git a/include/fc/log/appender.hpp b/include/fc/log/appender.hpp index 25fd222ffe909c05adac59e97e3f47e73db6443c..1b0fb43ee7d67897d2971a2cf3653ed2d739623f 100644 --- a/include/fc/log/appender.hpp +++ b/include/fc/log/appender.hpp @@ -33,7 +33,8 @@ namespace fc { milliseconds_since_epoch, /// 1685696704999ms iso_8601_seconds, /// 2023-06-02T09:05:41 iso_8601_milliseconds, /// 2023-06-02T09:05:10.580 - iso_8601_microseconds /// 2023-06-02T09:05:06.894046 + iso_8601_microseconds, /// 2023-06-02T09:05:06.894046 + iso_8601_realtime_microseconds /// Real wall-clock time (bypasses libfaketime) }; typedef fc::shared_ptr ptr; @@ -51,9 +52,10 @@ namespace fc { virtual void log( const log_message& m ) = 0; }; } -FC_REFLECT_ENUM( fc::appender::time_format, +FC_REFLECT_ENUM( fc::appender::time_format, (milliseconds_since_hour) (milliseconds_since_epoch) (iso_8601_seconds) (iso_8601_milliseconds) - (iso_8601_microseconds) ) + (iso_8601_microseconds) + (iso_8601_realtime_microseconds) ) diff --git a/src/log/appender.cpp b/src/log/appender.cpp index 588e6565ffc2834f075af203c6ef69bd3b60dfae..7494fe0ef44517cc10ee9e19a71c62ace309b388 100644 --- a/src/log/appender.cpp +++ b/src/log/appender.cpp @@ -9,6 +9,12 @@ #include #include #include "console_defines.h" +#include + +#ifndef _WIN32 +#include +#include +#endif namespace fc { @@ -59,6 +65,23 @@ namespace fc { case appender::time_format::iso_8601_microseconds: result << time.to_iso_string_in_microseconds(); break; + case appender::time_format::iso_8601_realtime_microseconds: + { +#ifndef _WIN32 + // Use syscall directly to bypass libfaketime interception + struct timespec ts; + syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts); + std::time_t seconds = ts.tv_sec; + std::tm utc_tm; + gmtime_r(&seconds, &utc_tm); + result << std::put_time(&utc_tm, "%Y-%m-%dT%H:%M:%S") + << '.' << std::setfill('0') << std::setw(6) << (ts.tv_nsec / 1000); +#else + // On Windows, just use regular time (libfaketime is Linux-only anyway) + result << time.to_iso_string_in_microseconds(); +#endif + } + break; case appender::time_format::milliseconds_since_hour: default: result << (time.time_since_epoch().count() % (1000ll * 1000ll * 60ll * 60)) / 1000 << "ms";