Skip to content

Commit 550ff88

Browse files
authored
Merge pull request #199 from bengouss/feature/milliseconds-since-epoch
feat: Add Milliseconds since Epoch option to logger
2 parents 292b3a7 + 6ca9628 commit 550ff88

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/core/flux_logging/flxLogger.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "flxUtils.h"
2020
#include <string.h>
2121
#include <time.h>
22+
#include <sys/time.h>
2223

2324
//----------------------------------------------------------------------------
2425
// Our time rate/metrics class
@@ -367,6 +368,10 @@ void flxLogger::updateTimeParameterName(void)
367368
timeTitle = "Time (millis)";
368369
break;
369370

371+
case TimeStampEpochMillis:
372+
timeTitle = "Time ms (Epoch)";
373+
break;
374+
370375
case TimeStampEpoch:
371376
timeTitle = "Time (Epoch)";
372377
break;
@@ -424,6 +429,8 @@ std::string flxLogger::get_timestamp(void)
424429
time_t t_now;
425430
time(&t_now);
426431
struct tm *tmLocal = localtime(&t_now);
432+
struct timeval tv;
433+
gettimeofday(&tv, nullptr);
427434
switch (_timestampType)
428435
{
429436
case TimeStampMillis:
@@ -434,6 +441,10 @@ std::string flxLogger::get_timestamp(void)
434441
snprintf(szBuffer, sizeof(szBuffer), "%ld", t_now);
435442
break;
436443

444+
case TimeStampEpochMillis:
445+
snprintf(szBuffer, sizeof(szBuffer), "%ld%03d", tv.tv_sec, tv.tv_usec/1000);
446+
break;
447+
437448
case TimeStampDateTimeUSA:
438449
strftime(szBuffer, sizeof(szBuffer), "%m-%d-%G %T", tmLocal);
439450
break;

src/core/flux_logging/flxLogger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ class flxLogger : public flxActionType<flxLogger>
256256
TimeStampNone,
257257
TimeStampMillis,
258258
TimeStampEpoch,
259+
TimeStampEpochMillis,
259260
TimeStampDateTimeUSA,
260261
TimeStampDateTime,
261262
TimeStampISO8601,
@@ -269,6 +270,7 @@ class flxLogger : public flxActionType<flxLogger>
269270
{{"No Timestamp", TimeStampNone},
270271
{"Milliseconds since program start", TimeStampMillis},
271272
{"Seconds since Epoch", TimeStampEpoch},
273+
{"Milliseconds since Epoch", TimeStampEpochMillis},
272274
{"Date Time - USA Date format", TimeStampDateTimeUSA},
273275
{"Date Time", TimeStampDateTime},
274276
{"ISO8601 Timestamp", TimeStampISO8601},

0 commit comments

Comments
 (0)