From b69f2eeaf4afcf1ba182c8392401cd50b1e470af Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Sat, 16 Oct 2021 16:13:32 +0100 Subject: [PATCH] Make it possible to silence timestamp, process and thread info. --- log.cpp | 13 +++++++++---- log.h | 8 +++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/log.cpp b/log.cpp index 5edad1d..629c071 100644 --- a/log.cpp +++ b/log.cpp @@ -160,14 +160,19 @@ namespace dechamps_cpplog { thread.join(); } - Logger::Logger(LogSink* sink) { + Logger::Logger(LogSink* sink, const Options& options) { if (sink == nullptr) return; enabledState.emplace(*sink); + auto& stream = enabledState->stream; - FILETIME now = { 0 }; - GetSystemTimeAsFileTimeFunction()(&now); - enabledState->stream << FormatFiletimeISO8601(now) << " " << GetCurrentProcessId() << " " << GetCurrentThreadId() << " "; + if (options.prependTime) { + FILETIME now = { 0 }; + GetSystemTimeAsFileTimeFunction()(&now); + stream << FormatFiletimeISO8601(now) << " "; + } + if (options.prependProcessId) stream << GetCurrentProcessId() << " "; + if (options.prependThreadId) stream << GetCurrentThreadId() << " "; } Logger::~Logger() { diff --git a/log.h b/log.h index b75e39f..c43bd6a 100644 --- a/log.h +++ b/log.h @@ -81,7 +81,13 @@ namespace dechamps_cpplog { class Logger final { public: - explicit Logger(LogSink* sink); + struct Options final { + bool prependTime = true; + bool prependProcessId = true; + bool prependThreadId = true; + }; + + explicit Logger(LogSink* sink, const Options& options = {}); ~Logger(); template friend Logger&& operator<<(Logger&& lhs, T&& rhs) {