blob: c935522bcae7ebfbf84916cb9e6bb56089eb3dfd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
// Copyright Epic Games, Inc. All Rights Reserved.
#include "inprocsessionlogsink.h"
#include <zencore/logbase.h>
namespace zen {
/// Bias in seconds from DateTime epoch (year 1) to Unix epoch (1970).
static constexpr uint64_t UnixEpochBiasSeconds = uint64_t(double(1970 - 1) * 365.2425) * 86400;
static DateTime
TimePointToDateTime(logging::LogClock::time_point Time)
{
// DateTime ticks are 100 ns each. Splitting the time_point into whole-second
// and sub-second parts and converting both lets us preserve sub-second
// precision; the previous implementation truncated to seconds, which made
// every entry land at .000 ms in tail / dashboard renderings.
auto Duration = Time.time_since_epoch();
auto Seconds = std::chrono::duration_cast<std::chrono::seconds>(Duration);
auto SubSecondNanos = std::chrono::duration_cast<std::chrono::nanoseconds>(Duration - Seconds);
uint64_t SecondsTicks = (UnixEpochBiasSeconds + static_cast<uint64_t>(Seconds.count())) * TimeSpan::TicksPerSecond;
uint64_t SubSecondTicks = static_cast<uint64_t>(SubSecondNanos.count()) / static_cast<uint64_t>(TimeSpan::NanosecondsPerTick);
return DateTime{SecondsTicks + SubSecondTicks};
}
void
InProcSessionLogSink::Log(const logging::LogMessage& Msg)
{
// Route through the service-level AppendLog so the log-appended
// callback fires — otherwise WS subscribers tailing the self-session
// don't see in-proc lines until they reload and re-fetch via HTTP.
m_Service.AppendLog(m_SessionId,
SessionsService::LogEntryInput{
.Timestamp = TimePointToDateTime(Msg.GetTime()),
.Level = Msg.GetLevel(),
.LoggerName = Msg.GetLoggerName(),
.Message = Msg.GetPayload(),
});
}
} // namespace zen
|