blob: 9982859b6c98c11d75e359d8f8f5c66870acdb5e (
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
|
// 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)
{
auto Duration = Time.time_since_epoch();
auto Seconds = std::chrono::duration_cast<std::chrono::seconds>(Duration);
uint64_t Ticks = (UnixEpochBiasSeconds + static_cast<uint64_t>(Seconds.count())) * TimeSpan::TicksPerSecond;
return DateTime{Ticks};
}
void
InProcSessionLogSink::Log(const logging::LogMessage& Msg)
{
Ref<SessionsService::Session> Session = m_Service.GetSession(m_SessionId);
if (!Session)
{
return;
}
SessionsService::LogEntry Entry{
.Timestamp = TimePointToDateTime(Msg.GetTime()),
.Level = std::string(logging::ToStringView(Msg.GetLevel())),
.Message = std::string(Msg.GetPayload()),
};
Session->AppendLog(std::move(Entry));
}
} // namespace zen
|