RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
RST::Log::ConsoleSink Class Reference

Writes colored lines to std::cout or another stream. More...

#include <RST/log/Sinks/ConsoleSink.hpp>

Inheritance diagram for RST::Log::ConsoleSink:
RST::Log::ASink RST::Log::ISink

Public Member Functions

 ConsoleSink (std::ostream &target=std::cout)
 
void setColor (LogLevel level, std::string_view colorCode)
 Sets the ANSI color of level; see Terminal.
 
void setColorEnabled (bool enabled) noexcept
 
bool isColorEnabled () const noexcept
 
- Public Member Functions inherited from RST::Log::ASink
 ASink ()
 
 ~ASink () override
 
void write (const LogMessage &message) final
 Receives a message from a logger.
 
void flush () final
 
void setLevel (LogLevel level) noexcept final
 Minimum level accepted by this sink.
 
LogLevel getLevel () const noexcept final
 
bool shouldLog (LogLevel level) const noexcept final
 
void setFormatter (std::shared_ptr< Formatter > formatter) final
 Shares a Formatter between sinks.
 
void setPattern (std::string_view pattern) final
 Formats the messages with pattern; see Formatter.
 
- Public Member Functions inherited from RST::Log::ISink
virtual ~ISink ()=default
 

Protected Member Functions

void log (const LogMessage &message) override
 Writes one message; called with the sink mutex locked.
 
void flushSink () override
 Flushes the output; called with the sink mutex locked.
 
- Protected Member Functions inherited from RST::Log::ASink
std::string_view formatted (const LogMessage &message)
 The message formatted with the sink pattern.
 
std::mutex & sinkMutex () noexcept
 

Detailed Description

Writes colored lines to std::cout or another stream.

Colors are enabled when the stream is a terminal that supports them.

Constructor & Destructor Documentation

◆ ConsoleSink()

RST::Log::ConsoleSink::ConsoleSink ( std::ostream &  target = std::cout)
explicit

Member Function Documentation

◆ setColor()

void RST::Log::ConsoleSink::setColor ( LogLevel  level,
std::string_view  colorCode 
)

Sets the ANSI color of level; see Terminal.

◆ setColorEnabled()

void RST::Log::ConsoleSink::setColorEnabled ( bool  enabled)
inlinenoexcept

◆ isColorEnabled()

bool RST::Log::ConsoleSink::isColorEnabled ( ) const
inlinenoexcept

◆ log()

void RST::Log::ConsoleSink::log ( const LogMessage &  message)
overrideprotectedvirtual

Writes one message; called with the sink mutex locked.

Implements RST::Log::ASink.

◆ flushSink()

void RST::Log::ConsoleSink::flushSink ( )
overrideprotectedvirtual

Flushes the output; called with the sink mutex locked.

Reimplemented from RST::Log::ASink.


The documentation for this class was generated from the following file: