27 for (
const auto it : *
this)
51 const auto now = std::chrono::system_clock::now();
52 const auto t = std::chrono::system_clock::to_time_t(now);
53 const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
55 localtime_s(&tm_info, &t);
56 std::ostringstream ts;
57 ts << std::put_time(&tm_info,
"%Y-%m-%d %H:%M:%S")
58 <<
"." << std::setfill(
'0') << std::setw(3) << ms.count();
60 return msgType +
"\t| " + ts.str() +
"\t| " + msg;
65 return LogStream(*
this,
static_cast<int>(type));
71 : m_logger(&logger), m_type(type), m_active(true)
76 : m_logger(other.m_logger), m_type(other.m_type),
77 m_stream(std::move(other.m_stream)), m_active(other.m_active)
79 other.m_active =
false;
97 int size_needed = WideCharToMultiByte(CP_UTF8, 0, value.c_str(),
static_cast<int>(value.size()),
nullptr, 0,
nullptr,
nullptr);
98 std::string utf8(size_needed, 0);
99 WideCharToMultiByte(CP_UTF8, 0, value.c_str(),
static_cast<int>(value.size()), &utf8[0], size_needed,
nullptr,
nullptr);
110 return *
this << std::wstring(value);
RAII stream object that collects log output and dispatches it on destruction.
LogStream(Logger &logger, int type)
LogStream & operator<<(const T &value)
std::ostringstream m_stream
Singleton logging facility that dispatches formatted messages to LogOutput sinks.
static Logger * m_instance
LogStream operator()(Logger::LogType type)
Create a LogStream for the given severity level.
void dispatchLog(int type, const std::string &msg)
Send a pre-formatted message to all registered outputs.
static std::string formatLog(int type, const std::string &msg)
Format a log message with a severity prefix and timestamp.
static void init()
Initialise the logging subsystem (creates console and file outputs).