Skip to main content

AVxcelerate Simulation Framework 2025 R2 SP02

logging

Last update: 19.09.2025
1
3
4#pragma once
5
6#include "core/logging/console_logger.h"
7#include "core/logging/i_logger.h"
8#include <memory>
9#include <vector>
10
16{
17namespace core
18{
19namespace logging
20{
21
28{
29 public:
30 using ILoggerContainer = std::vector<std::unique_ptr<ILogger>>;
31
32 virtual ~LoggingInstance() = default;
33
34 LoggingInstance(const LoggingInstance&) = delete;
35 LoggingInstance& operator=(const LoggingInstance&) = delete;
36
43
46 void RegisterLogger(std::unique_ptr<ILogger> logger) { loggers_.push_back(std::move(logger)); }
47
49 void ClearLoggers() { loggers_.clear(); }
50
52 const ILoggerContainer& GetLoggers() const { return loggers_; }
53
57 void Log(LogLevel level, std::string_view message)
58 {
59 for (const auto& logger : loggers_)
60 {
61 if (logger)
62 {
63 logger->Log(level, message);
64 }
65 }
66 }
67
70 void SetLogLevel(LogLevel log_level)
71 {
72 for (const auto& logger : loggers_)
73 {
74 if (logger)
75 {
76 logger->SetCurrentLogLevel(log_level);
77 }
78 }
79 }
80
81 private:
82 LoggingInstance() { RegisterLogger(std::make_unique<simulation_framework::core::logging::ConsoleLogger>()); };
83
84 ILoggerContainer loggers_;
85};
86
89static inline void SetLogLevel(LogLevel log_level) noexcept
90{
91 LoggingInstance::GetInstance().SetLogLevel(log_level);
92}
93
97static inline void Debug(std::string_view message) noexcept
98{
99 LoggingInstance::GetInstance().Log(LogLevel::kDebug, message);
100}
101
105static inline void Info(std::string_view message) noexcept
106{
107 LoggingInstance::GetInstance().Log(LogLevel::kInfo, message);
108}
109
113static inline void Warning(std::string_view message) noexcept
114{
115 LoggingInstance::GetInstance().Log(LogLevel::kWarning, message);
116}
117
121static inline void Error(std::string_view message) noexcept
122{
123 LoggingInstance::GetInstance().Log(LogLevel::kError, message);
124}
125
126} // namespace logging
127} // namespace core
128} // namespace simulation_framework
This is the concrete Topic class that can be used for creation of a communication channel with given ...
Definition topic.h:38
A singleton class to be used for all logging purposes. It can be used to register additional loggers ...
Definition logging.h:28
void Log(LogLevel level, std::string_view message)
Log a message on the logging interface.
Definition logging.h:57
const ILoggerContainer & GetLoggers() const
Return a const reference to the container of registered loggers.
Definition logging.h:52
void SetLogLevel(LogLevel log_level)
Set Log level of all registered loggers.
Definition logging.h:70
static LoggingInstance & GetInstance()
Returns a reference to global singleton logging instance.
Definition logging.h:38
void ClearLoggers()
Remove all currently registered loggers.
Definition logging.h:49
void RegisterLogger(std::unique_ptr< ILogger > logger)
Register a new logger.
Definition logging.h:46
The namespace for all core functionalities under namespace simulation_framework.
The top namespace for simulation framework.

Connect with Ansys