FileSink
Lines land in a memory buffer and reach the disk from a flusher thread every 200 ms, when the buffer fills, on any Error/Fatal line, on Flush, and from the crash handler's pre-report hook — never with a syscall per line. The old sink wrote std::endl per message, one flush each, which was a measurable share of a Debug frame under the render-init spam. The file is opened shared-read so the crash reporter's tail copy and a tail tool still see it mid-session.
- Module
- Logging
- Header
#include "Logging/Logger.h"- Namespace
Mowo
No thread that logs ever waits on the disk. The flusher opens the file, swaps the buffer out under the lock and writes it with the lock released; an Error line only wakes it. The lock used to be held across fwrite and fflush, and on a disk taking seconds per write (a project on a busy HDD) every logging thread — the render thread included — froze behind it: the owner's 14 s and 19 s "submit" stalls were the render thread waiting to append one line. A disk that takes nothing for long enough costs lines, counted in the file, never a frame.
Constructors
| Signature | Name | Description |
|---|---|---|
explicit FileSink(const std::string& filepath, bool append = false, std::functio… | FileSink | |
~FileSink() override | ~FileSink |
Public functions
| Returns | Name | Description |
|---|---|---|
void | Write | |
void | Flush | |
void | CrashFlush | |
bool | IsOpen | Waits for the flusher's open attempt. |
const std::string& | GetFilepath | |
void | SetWriteStallForTest | Holds every disk write of every FileSink this long — a test's stand-in for a disk that takes seconds per write. |
Function details
FileSink
explicit FileSink(const std::string& filepath, bool append = false, std::function<void()> afterOpen = {})~FileSink
~FileSink() overrideWrite
void Write(const LogMessage& msg) overrideFlush
void Flush() overrideCrashFlush
void CrashFlush() overrideIsOpen
bool IsOpen()Waits for the flusher's open attempt.
GetFilepath
const std::string& GetFilepath() constSetWriteStallForTest
static void SetWriteStallForTest(int32_t milliseconds)Holds every disk write of every FileSink this long — a test's stand-in for a disk that takes seconds per write.