Skip to content

EntropyEngine::Core::Logging::ConsoleSink

Log sink that outputs to console. More…

#include <ConsoleSink.h>

Inherits from EntropyEngine::Core::Logging::ILogSink

Name
virtual voidwrite(const LogEntry & entry) override
Write a log entry to this sink.
virtual boolshouldLog(LogLevel level) const override
Check if this sink accepts logs at the given level.
voidsetUseColor(bool useColor)
Enable/disable color output.
voidsetShowThreadId(bool show)
Enable/disable thread ID in output.
voidsetShowLocation(bool show)
Enable/disable source location in output.
virtual voidsetMinLevel(LogLevel level) override
Set the minimum log level for this sink.
virtual voidflush() override
Flush any buffered data.
ConsoleSink(bool useColor =true, bool showThreadId =true)

Public Functions inherited from EntropyEngine::Core::Logging::ILogSink

Name
virtual~ILogSink() =default
class EntropyEngine::Core::Logging::ConsoleSink;

Log sink that outputs to console.

ConsoleSink provides formatted output to the terminal with optional color coding based on log severity. Error and Fatal messages are directed to stderr while other levels use stdout, allowing flexible output redirection.

Features:

  • Color-coded output by log level for visual distinction
  • Thread-safe to prevent garbled output from concurrent logging
  • Configurable format options (thread IDs, source locations)
  • Intelligent stream selection (stderr for errors, stdout for others)

Usage tip: Redirect stdout while preserving error visibility: ./myapp > output.log # Errors remain visible on console

virtual void write(
const LogEntry & entry
) override

Write a log entry to this sink.

Parameters:

  • entry The log entry to write

Reimplements: EntropyEngine::Core::Logging::ILogSink::write

Processes and outputs a log entry according to the sink’s implementation. Must be thread-safe. May buffer output for performance.

void MyCustomSink::write(const LogEntry& entry) {
if (!shouldLog(entry.level)) return;
auto formatted = formatEntry(entry);
sendToDestination(formatted);
}
virtual bool shouldLog(
LogLevel level
) const override

Check if this sink accepts logs at the given level.

Parameters:

  • level The log level to check

Return: true if the sink will process logs at this level

Reimplements: EntropyEngine::Core::Logging::ILogSink::shouldLog

Allows different sinks to filter messages independently based on their configuration.

// Console shows only warnings and above
consoleSink->setMinLevel(LogLevel::Warning);
// File captures all messages including trace
fileSink->setMinLevel(LogLevel::Trace);
inline void setUseColor(
bool useColor
)

Enable/disable color output.

Parameters:

  • useColor true to enable colors, false for plain text

Disable when terminal doesn’t support ANSI or piping to file.

inline void setShowThreadId(
bool show
)

Enable/disable thread ID in output.

Parameters:

  • show true to include thread IDs, false to hide them

Useful for multithreaded debugging but noisy in single-threaded apps.

inline void setShowLocation(
bool show
)

Enable/disable source location in output.

Parameters:

  • show true to include file:line info, false to hide it

Shows file:line info. Helpful for debugging but verbose for production.

virtual void setMinLevel(
LogLevel level
) override

Set the minimum log level for this sink.

Parameters:

  • level The minimum level to accept (inclusive)

Reimplements: EntropyEngine::Core::Logging::ILogSink::setMinLevel

Controls verbosity of this specific sink. Each sink maintains its own level setting for flexible log routing.

// Development configuration
sink->setMinLevel(LogLevel::Debug);
// Production configuration
sink->setMinLevel(LogLevel::Warning);
// Debugging mode
sink->setMinLevel(LogLevel::Trace);
virtual void flush() override

Flush any buffered data.

Reimplements: EntropyEngine::Core::Logging::ILogSink::flush

Forces immediate write of buffered data. Called after critical messages and during shutdown. Sinks without buffering can implement as no-op.

inline explicit ConsoleSink(
bool useColor =true,
bool showThreadId =true
)

Updated on 2026-01-26 at 17:14:35 -0500