Skip to main content

Logger Class

Logger implementation with configurable output sinks. More...

Declaration

class helios::util::log::Logger { ... }

Public Constructors Index

Logger (std::string scope)

Creates a new Logger, tagged with a specific scope. More...

Public Member Functions Index

voidenable (bool enable) noexcept

Enables or disables log output for this Logger instance. More...

voidaddSink (std::shared_ptr< LogSink > sink)

Adds an output sink to this logger. More...

voidclearSinks () noexcept

Removes all sinks from this logger. More...

size_tsinkCount () const noexcept

Returns the number of attached sinks. More...

voidwarn (const std::string &msg) const noexcept

Writes a warning message if logging is enabled. More...

voiddebug (const std::string &msg) const noexcept

Writes a debug message if logging is enabled. More...

voidinfo (const std::string &msg) const noexcept

Writes an info message if logging is enabled. More...

voiderror (const std::string &msg) const noexcept

Writes an error message if logging is enabled. More...

Private Member Functions Index

voiddispatch (LogLevel level, const std::string &msg) const noexcept

Dispatches a message to all registered sinks. More...

Private Member Attributes Index

const std::stringscope_ = "default"
boolenabled_ = true

Flag to indicate whether this Logger's output is enabled. More...

std::vector< std::shared_ptr< LogSink > >sinks_

Collection of output sinks. More...

std::mutexsinkMutex_

Mutex for thread-safe sink access. More...

Description

Logger implementation with configurable output sinks.

This logger supports multiple output destinations through LogSink instances. By default, it writes to stdout, but sinks can be added or replaced to redirect output to ImGui widgets, files, or other destinations.

```cpp // Add ImGui sink while keeping console output logger.addSink(imguiSink);

// Replace all sinks (ImGui only) logger.clearSinks(); logger.addSink(imguiSink); ```

Definition at line 35 of file Logger.ixx.

Public Constructors

Logger()

helios::util::log::Logger::Logger (std::string scope)
inline explicit

Creates a new Logger, tagged with a specific scope.

Parameters
scope

The textual scope used as a prefix in log output (e.g. "helios::rendering").

Definition at line 90 of file Logger.ixx.

90 explicit Logger(std::string scope) :
91 scope_(std::move(scope)) {}

Public Member Functions

addSink()

void helios::util::log::Logger::addSink (std::shared_ptr< LogSink > sink)
inline

Adds an output sink to this logger.

Parameters
sink

Shared pointer to the sink to add.

Definition at line 107 of file Logger.ixx.

107 void addSink(std::shared_ptr<LogSink> sink) {
108 std::lock_guard<std::mutex> lock(sinkMutex_);
109 sinks_.push_back(std::move(sink));
110 }

clearSinks()

void helios::util::log::Logger::clearSinks ()
inline noexcept

Removes all sinks from this logger.

Definition at line 115 of file Logger.ixx.

115 void clearSinks() noexcept {
116 std::lock_guard<std::mutex> lock(sinkMutex_);
117 sinks_.clear();
118 }

debug()

void helios::util::log::Logger::debug (const std::string & msg)
inline noexcept

Writes a debug message if logging is enabled.

Parameters
msg

The message to write.

Definition at line 144 of file Logger.ixx.

144 void debug(const std::string& msg) const noexcept {
145 dispatch(LogLevel::Debug, msg);
146 }

Reference helios::util::log::Debug.

enable()

void helios::util::log::Logger::enable (bool enable)
inline noexcept

Enables or disables log output for this Logger instance.

Parameters
enable

true to enable output, false to disable it.

Definition at line 98 of file Logger.ixx.

98 void enable(bool enable) noexcept {
99 enabled_ = enable;
100 }

Reference enable.

Referenced by enable.

error()

void helios::util::log::Logger::error (const std::string & msg)
inline noexcept

Writes an error message if logging is enabled.

Parameters
msg

The message to write.

Definition at line 162 of file Logger.ixx.

162 void error(const std::string& msg) const noexcept {
163 dispatch(LogLevel::Error, msg);
164 }

Reference helios::util::log::Error.

info()

void helios::util::log::Logger::info (const std::string & msg)
inline noexcept

Writes an info message if logging is enabled.

Parameters
msg

The message to write.

Definition at line 153 of file Logger.ixx.

153 void info(const std::string& msg) const noexcept {
154 dispatch(LogLevel::Info, msg);
155 }

Reference helios::util::log::Info.

sinkCount()

size_t helios::util::log::Logger::sinkCount ()
inline nodiscard noexcept

Returns the number of attached sinks.

Returns

The number of sinks currently attached to this logger.

Definition at line 125 of file Logger.ixx.

125 [[nodiscard]] size_t sinkCount() const noexcept {
126 std::lock_guard<std::mutex> lock(sinkMutex_);
127 return sinks_.size();
128 }

warn()

void helios::util::log::Logger::warn (const std::string & msg)
inline noexcept

Writes a warning message if logging is enabled.

Parameters
msg

The message to write.

Definition at line 135 of file Logger.ixx.

135 void warn(const std::string& msg) const noexcept {
136 dispatch(LogLevel::Warn, msg);
137 }

Reference helios::util::log::Warn.

Private Member Functions

dispatch()

void helios::util::log::Logger::dispatch (LogLevel level, const std::string & msg)
inline noexcept

Dispatches a message to all registered sinks.

Parameters
level

The log level of the message.

msg

The message to dispatch.

Definition at line 61 of file Logger.ixx.

61 void dispatch(LogLevel level, const std::string& msg) const noexcept {
62 if (!enabled_) return;
63
64 std::lock_guard<std::mutex> lock(sinkMutex_);
65 if (sinks_.empty()) {
66 // Fallback to stdout if no sinks configured
67 const char* levelStr = "";
68 switch (level) {
69 case LogLevel::Debug: levelStr = "[DEBUG]"; break;
70 case LogLevel::Info: levelStr = "[INFO]"; break;
71 case LogLevel::Warn: levelStr = "[WARN]"; break;
72 case LogLevel::Error: levelStr = "[ERROR]"; break;
73 }
74 std::cout << levelStr << "[" << scope_ << "] " << msg << std::endl;
75 } else {
76 for (const auto& sink : sinks_) {
77 if (sink) {
78 sink->write(level, scope_, msg);
79 }
80 }
81 }
82 }

Private Member Attributes

enabled_

bool helios::util::log::Logger::enabled_ = true

Flag to indicate whether this Logger's output is enabled.

Definition at line 43 of file Logger.ixx.

43 bool enabled_ = true;

scope_

const std::string helios::util::log::Logger::scope_ = "default"

Definition at line 38 of file Logger.ixx.

38 const std::string scope_ = "default";

sinkMutex_

std::mutex helios::util::log::Logger::sinkMutex_
mutable

Mutex for thread-safe sink access.

Definition at line 53 of file Logger.ixx.

53 mutable std::mutex sinkMutex_;

sinks_

std::vector<std::shared_ptr<LogSink> > helios::util::log::Logger::sinks_

Collection of output sinks.

Definition at line 48 of file Logger.ixx.

48 std::vector<std::shared_ptr<LogSink>> sinks_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.