11#include < odr/logger.hpp>
22
33#include < algorithm>
4- #include < chrono>
54#include < filesystem>
65#include < iomanip>
76#include < iostream>
@@ -16,7 +15,7 @@ class NullLogger final : public Logger {
1615public:
1716 [[nodiscard]] bool will_log (LogLevel) const final { return false ; }
1817
19- void log_impl (LogLevel, const std::string &,
18+ void log_impl (Time, LogLevel, const std::string &,
2019 const std::source_location &) final {
2120 // Do nothing
2221 }
@@ -43,9 +42,9 @@ class StdioLogger final : public Logger {
4342 return level >= m_level;
4443 }
4544
46- void log_impl (LogLevel level, const std::string &message,
45+ void log_impl (Time time, LogLevel level, const std::string &message,
4746 const std::source_location &location) final {
48- print_head (*m_output, m_name , level, location, m_format);
47+ print_head (*m_output, time , level, m_name , location, m_format);
4948 *m_output << message << " \n " ;
5049 }
5150
@@ -75,13 +74,13 @@ class TeeLogger final : public Logger {
7574 });
7675 }
7776
78- void log_impl (LogLevel level, const std::string &message,
77+ void log_impl (Time time, LogLevel level, const std::string &message,
7978 const std::source_location &location) final {
8079 for (const auto &logger : m_loggers) {
8180 if (!logger->will_log (level)) {
8281 continue ;
8382 }
84- logger->log (level, message, location);
83+ logger->log (level, message, time, location);
8584 }
8685 }
8786
@@ -133,14 +132,13 @@ Logger::create_tee(const std::vector<std::shared_ptr<Logger>> &loggers) {
133132 return std::make_unique<TeeLogger>(loggers);
134133}
135134
136- void Logger::print_head (std::ostream &out, const std::string &name,
137- LogLevel level, const std::source_location &location,
135+ void Logger::print_head (std::ostream &out, Time time, LogLevel level,
136+ const std::string &name,
137+ const std::source_location &location,
138138 const LogFormat &format) {
139139 if (!format.time_format .empty ()) {
140- auto now = std::chrono::system_clock::now ();
141- auto time = std::chrono::system_clock::to_time_t (now);
142- out << std::put_time (std::localtime (&time), format.time_format .c_str ())
143- << " " ;
140+ auto t = Clock::to_time_t (time);
141+ out << std::put_time (std::localtime (&t), format.time_format .c_str ()) << " " ;
144142 }
145143
146144 if (format.level_width > 0 ) {
0 commit comments