Skip to main content

AVxcelerate Simulation Framework 2026 R1 SP01

File logging.h

Last update: 22.04.2026

Location: core/logging/logging.h

Classes

Namespaces

Includes

  • core/export/simfwk_core_export.h
  • core/logging/console_logger.h
  • core/logging/i_logger.h
  • <string_view>

Included by

Source



#ifndef SIMFWK_CORE_LOGGING_LOGGING_H
#define SIMFWK_CORE_LOGGING_LOGGING_H

#include "core/export/simfwk_core_export.h"
#include "core/logging/console_logger.h"
#include "core/logging/i_logger.h"
#include <memory>
#include <string_view>
#include <vector>

namespace simulation_framework
{
namespace core
{
namespace logging
{

class SIMFWK_CORE_API LoggingInstance
{
  public:
    using ILoggerContainer = std::vector<std::unique_ptr<ILogger>>;

    virtual ~LoggingInstance() = default;

    LoggingInstance(const LoggingInstance&) = delete;
    LoggingInstance& operator=(const LoggingInstance&) = delete;

    static LoggingInstance& GetInstance()
    {
        static LoggingInstance log_instance;
        return log_instance;
    }

    void RegisterLogger(std::unique_ptr<ILogger> logger) { loggers_.push_back(std::move(logger)); }

    void ClearLoggers() { loggers_.clear(); }

    const ILoggerContainer& GetLoggers() const { return loggers_; }

    void Log(LogLevel level, std::string_view message)
    {
        for (const auto& logger : loggers_)
        {
            if (logger)
            {
                logger->Log(level, message);
            }
        }
    }

    void SetLogLevel(LogLevel log_level)
    {
        for (const auto& logger : loggers_)
        {
            if (logger)
            {
                logger->SetCurrentLogLevel(log_level);
            }
        }
    }

  private:
    LoggingInstance() { RegisterLogger(std::make_unique<simulation_framework::core::logging::ConsoleLogger>()); };

    ILoggerContainer loggers_;
};

static inline void SetLogLevel(LogLevel log_level) noexcept
{
    LoggingInstance::GetInstance().SetLogLevel(log_level);
}

static inline void Debug(std::string_view message) noexcept
{
    LoggingInstance::GetInstance().Log(LogLevel::kDebug, message);
}

static inline void Info(std::string_view message) noexcept
{
    LoggingInstance::GetInstance().Log(LogLevel::kInfo, message);
}

static inline void Warning(std::string_view message) noexcept
{
    LoggingInstance::GetInstance().Log(LogLevel::kWarning, message);
}

static inline void Error(std::string_view message) noexcept
{
    LoggingInstance::GetInstance().Log(LogLevel::kError, message);
}

}  // namespace logging
}  // namespace core
}  // namespace simulation_framework

#endif  // SIMFWK_CORE_LOGGING_LOGGING_H

Connect with Ansys