add RfcUtcTime compilation option (#152)
* log_output: use of getFastDateTimeString with RfcUtcTime format setting
This commit is contained in:
parent
a28bb9781c
commit
1ac2715bbb
|
@ -385,6 +385,13 @@ Possible values are:
|
|||
|
||||
https://tools.ietf.org/html/rfc3339
|
||||
|
||||
- `RfcUtcTime`
|
||||
|
||||
Chronicles will use the UTC but in human-readable format specified in
|
||||
RFC 3339: Date and Time on the Internet: Timestamps
|
||||
|
||||
https://tools.ietf.org/html/rfc3339
|
||||
|
||||
- `UnixTime`
|
||||
|
||||
Chronicles will write a single float value for the number
|
||||
|
|
|
@ -454,29 +454,35 @@ proc getSecondsPart(timestamp: Time): string =
|
|||
res[5] = chr(ord('0') + (tmp mod 10))
|
||||
res
|
||||
|
||||
proc getFastDateTimeString(): string =
|
||||
proc getFastDateTimeString(useUtc: bool): string =
|
||||
## if useUtc is true, utc time is used and Z for the timezone part.
|
||||
## if useUtc is false, the local time will be used and the time zone will be obtained each time.
|
||||
let
|
||||
timestamp = getFastTime()
|
||||
minutes = timestamp.toUnix() div 60
|
||||
|
||||
if minutes != cachedMinutes:
|
||||
cachedMinutes = minutes
|
||||
let datetime = timestamp.local()
|
||||
let datetime = if useUtc: timestamp.utc() else: timestamp.local()
|
||||
block:
|
||||
# Cache string representation of first part (without seconds)
|
||||
let tmp = datetime.format("yyyy-MM-dd HH:mm:")
|
||||
cachedTimeArray = toArray(17, tmp.toOpenArrayByte(0, 16))
|
||||
block:
|
||||
# Cache string representation of zone part
|
||||
let tmp = datetime.format("zzz")
|
||||
cachedZoneArray = toArray(6, tmp.toOpenArrayByte(0, 5))
|
||||
if not useUtc:
|
||||
# Cache string representation of zone part
|
||||
let tmp = datetime.format("zzz")
|
||||
cachedZoneArray = toArray(6, tmp.toOpenArrayByte(0, 5))
|
||||
|
||||
string.fromBytes(cachedTimeArray) & timestamp.getSecondsPart() &
|
||||
string.fromBytes(cachedZoneArray)
|
||||
let timeZone = if useUtc: "Z" else: string.fromBytes(cachedZoneArray)
|
||||
|
||||
string.fromBytes(cachedTimeArray) & timestamp.getSecondsPart() & timeZone
|
||||
|
||||
template timestamp(record): string =
|
||||
when record.timestamps == RfcTime:
|
||||
getFastDateTimeString()
|
||||
getFastDateTimeString(useUtc = false)
|
||||
elif record.timestamps == RfcUtcTime:
|
||||
getFastDateTimeString(useUtc = true)
|
||||
else:
|
||||
epochTimestamp()
|
||||
|
||||
|
|
|
@ -73,7 +73,8 @@ type
|
|||
TimestampsScheme* = enum
|
||||
NoTimestamps,
|
||||
UnixTime,
|
||||
RfcTime
|
||||
RfcTime,
|
||||
RfcUtcTime
|
||||
|
||||
ColorScheme* = enum
|
||||
NoColors,
|
||||
|
@ -257,6 +258,7 @@ proc sinkSpecsFromNode*(streamNode: NimNode): seq[SinkSpec] =
|
|||
of "notimestamps": setTimestamps(NoTimestamps)
|
||||
of "unixtime": setTimestamps(UnixTime)
|
||||
of "rfctime": setTimestamps(RfcTime)
|
||||
of "rfcutctime": setTimestamps(RfcUtcTime)
|
||||
else: discard
|
||||
|
||||
let dst = logDestinationFromNode(dstSpec)
|
||||
|
|
Loading…
Reference in New Issue