EntropyEngine::Core::Logging::ConsoleSink
EntropyEngine::Core::Logging::ConsoleSink
Section titled “EntropyEngine::Core::Logging::ConsoleSink”Log sink that outputs to console. More…
#include <ConsoleSink.h>
Inherits from EntropyEngine::Core::Logging::ILogSink
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| virtual void | write(const LogEntry & entry) override Write a log entry to this sink. |
| virtual bool | shouldLog(LogLevel level) const override Check if this sink accepts logs at the given level. |
| void | setUseColor(bool useColor) Enable/disable color output. |
| void | setShowThreadId(bool show) Enable/disable thread ID in output. |
| void | setShowLocation(bool show) Enable/disable source location in output. |
| virtual void | setMinLevel(LogLevel level) override Set the minimum log level for this sink. |
| virtual void | flush() override Flush any buffered data. |
| ConsoleSink(bool useColor =true, bool showThreadId =true) |
Additional inherited members
Section titled “Additional inherited members”Public Functions inherited from EntropyEngine::Core::Logging::ILogSink
| Name | |
|---|---|
| virtual | ~ILogSink() =default |
Detailed Description
Section titled “Detailed Description”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
Public Functions Documentation
Section titled “Public Functions Documentation”function write
Section titled “function write”virtual void write( const LogEntry & entry) overrideWrite 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);}function shouldLog
Section titled “function shouldLog”virtual bool shouldLog( LogLevel level) const overrideCheck 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 aboveconsoleSink->setMinLevel(LogLevel::Warning);
// File captures all messages including tracefileSink->setMinLevel(LogLevel::Trace);function setUseColor
Section titled “function setUseColor”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.
function setShowThreadId
Section titled “function setShowThreadId”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.
function setShowLocation
Section titled “function setShowLocation”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.
function setMinLevel
Section titled “function setMinLevel”virtual void setMinLevel( LogLevel level) overrideSet 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 configurationsink->setMinLevel(LogLevel::Debug);
// Production configurationsink->setMinLevel(LogLevel::Warning);
// Debugging modesink->setMinLevel(LogLevel::Trace);function flush
Section titled “function flush”virtual void flush() overrideFlush 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.
function ConsoleSink
Section titled “function ConsoleSink”inline explicit ConsoleSink( bool useColor =true, bool showThreadId =true)Updated on 2026-01-26 at 17:14:35 -0500