Skip to content

Commit 74d8d2a

Browse files
committed
feat(Log): Add system_clock time_point
1 parent 01d4bb9 commit 74d8d2a

6 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/LogCapture.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ namespace al
55
{
66
LogCapture::LogCapture(const eLogLevel level, std::source_location&& location) :
77
m_Level(level),
8+
m_Timestamp(std::chrono::system_clock::now()),
89
m_Location(location)
9-
{
10-
11-
}
10+
{}
1211

1312
LogCapture::~LogCapture()
1413
{
1514
m_Stream << '\n';
16-
Logger::PushMessage(m_Level, std::move(m_Location), std::move(m_Stream.str()));
15+
Logger::PushMessage(m_Level, std::move(m_Timestamp), std::move(m_Location), std::move(m_Stream.str()));
1716
}
1817
}

src/LogCapture.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include <chrono>
23
#include <source_location>
34
#include <sstream>
45
#include "LogLevel.hpp"
@@ -17,6 +18,7 @@ namespace al
1718

1819
private:
1920
const eLogLevel m_Level;
21+
std::chrono::system_clock::time_point m_Timestamp;
2022
std::source_location m_Location;
2123
std::ostringstream m_Stream;
2224

src/LogMessage.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#include "LogMessage.hpp"
22
#include "LogLevel.hpp"
3+
#include <chrono>
34

45
namespace al
56
{
6-
LogMessage::LogMessage(const eLogLevel level, std::source_location&& location, std::string&& message) :
7+
LogMessage::LogMessage(const eLogLevel level, std::chrono::system_clock::time_point&& timestamp, std::source_location&& location, std::string&& message) :
78
m_Level(level),
9+
m_Timestamp(timestamp),
810
m_Location(location),
911
m_Message(message)
1012
{
@@ -26,4 +28,8 @@ namespace al
2628
return m_Message;
2729
}
2830

31+
const std::chrono::system_clock::time_point &LogMessage::Timestamp() const
32+
{
33+
return m_Timestamp;
34+
}
2935
}

src/LogMessage.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ namespace al
88
class LogMessage
99
{
1010
public:
11-
LogMessage(const eLogLevel level, std::source_location&& location, std::string&& message);
11+
LogMessage(const eLogLevel level, std::chrono::system_clock::time_point&& timestamp, std::source_location&& location, std::string&& message);
1212
virtual ~LogMessage() = default;
1313

1414
const eLogLevel& Level() const;
1515
const std::source_location& Location() const;
1616
const std::string& Message() const;
17+
const std::chrono::system_clock::time_point& Timestamp() const;
1718

1819
private:
1920
const eLogLevel m_Level;
21+
const std::chrono::system_clock::time_point m_Timestamp;
2022
const std::source_location m_Location;
2123
const std::string m_Message;
2224

src/Logger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ namespace al
2424
Logger::GetInstance().InitImpl();
2525
}
2626

27-
void Logger::PushMessage(const eLogLevel level, std::source_location&& location, std::string&& message) noexcept
27+
void Logger::PushMessage(const eLogLevel level, std::chrono::system_clock::time_point&& timestamp, std::source_location&& location, std::string&& message) noexcept
2828
{
29-
auto msgPtr = std::make_shared<LogMessage>(level, std::move(location), std::move(message));
29+
auto msgPtr = std::make_shared<LogMessage>(level, std::move(timestamp), std::move(location), std::move(message));
3030

3131
Logger::GetInstance().QueueMessage(std::move(msgPtr));
3232
}

src/Logger.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace al
3333
static void Init();
3434

3535
protected:
36-
static void PushMessage(const eLogLevel level, std::source_location&& location, std::string&& message) noexcept;
36+
static void PushMessage(const eLogLevel level, std::chrono::system_clock::time_point&& timestamp, std::source_location&& location, std::string&& message) noexcept;
3737

3838
private:
3939
void CallSinks(LogMessagePtr msgPtr);

0 commit comments

Comments
 (0)