Create log timestamps in UTC to avoid local-time races
Use getTime().utc in both message constructors, document the timezone change, and cover concurrent construction and structured formatting. Restore ordinary logging calls in the parallel writer fixture. Validation: 32 unit tests and 29 regression tests pass. Timestamp sanitizer checks pass under UTC and non-UTC timezones. The full suite retains the known allocator reports in factory-state and allocator.
This commit is contained in:
1 parent
011780e6ab
commit
46245b3f1e
6 files changed
+48
-17
No files matched your search
@@ -73,6 +73,7 @@ type
|
||||
level*: Level
|
||||
err*: Option[ref Exception]
|
||||
ts*: DateTime
|
||||
## initLogMessage records the current instant in UTC.
|
||||
msg*: string
|
||||
additionalData*: JsonNode
|
||||
|
||||
@@ -217,12 +218,13 @@ proc initLogMessage*(
|
||||
msg: string,
|
||||
err: Option[ref Exception] = none[ref Exception](),
|
||||
additionalData: JsonNode = newJNull()): LogMessage =
|
||||
## Create a message with a UTC timestamp, avoiding local-time conversion.
|
||||
|
||||
LogMessage(
|
||||
scope: scope,
|
||||
level: lvl,
|
||||
err: err,
|
||||
ts: now(),
|
||||
ts: getTime().utc,
|
||||
msg: msg,
|
||||
additionalData: additionalData)
|
||||
|
||||
@@ -232,12 +234,13 @@ proc initLogMessage*(
|
||||
lvl: Level,
|
||||
msg: JsonNode,
|
||||
err: Option[ref Exception] = none[ref Exception]()): LogMessage =
|
||||
## Create a structured message with a UTC timestamp.
|
||||
|
||||
LogMessage(
|
||||
scope: scope,
|
||||
level: lvl,
|
||||
err: err,
|
||||
ts: now(),
|
||||
ts: getTime().utc,
|
||||
msg:
|
||||
if msg.hasKey("msg"): msg["msg"].getStr
|
||||
elif msg.hasKey("message"): msg["message"].getStr
|
||||
|
||||
Reference in new issue
Block a user