Skip to content

Commit

Permalink
Make it possible to silence timestamp, process and thread info.
Browse files Browse the repository at this point in the history
  • Loading branch information
dechamps committed Oct 16, 2021
1 parent 6c724ba commit b69f2ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 9 additions & 4 deletions log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 7 additions & 1 deletion log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T> friend Logger&& operator<<(Logger&& lhs, T&& rhs) {
Expand Down

0 comments on commit b69f2ee

Please sign in to comment.