Log File Class
LogFile writes time-stamped lines to a file. WriteLine() is thread safe.
Contents
Overview
LogFile is built on std::ofstream. WriteLine() formats the time stamp, message and new line and writes them under a mutex, so several threads can share one log without mixing lines.
LogFile log;
log.Open("server.log"); // Append, creating the file if needed
log.WriteLine("Server started on port 8443");
Functions
bool LogFile::Open(const std::string &fname)Opens for append, creating the file. Returns true if successful.
bool LogFile::OverWrite(const std::string &fname) / CreateCreates or truncates the file.
bool LogFile::WriteLine(std::string_view message)Writes "date time message" and a new line, then flushes.
bool LogFile::Write(std::string_view text)Writes text as-is.
LogFile &LogFile::operator<<(const T &value)Stream insertion for building a line. Not thread safe across calls.
void LogFile::Close() / bool Flush() / bool IsOpen() constFile control.