Aria
2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Toggle main menu visibility
Loading...
Searching...
No Matches
logger.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
aria/abi/export.hpp
"
4
#include <functional>
5
#include <memory>
6
#include <string_view>
7
8
namespace
aria::runtime
{
9
10
enum class
LogLevel
{
Trace
,
Debug
,
Info
,
Warn
,
Error
,
Fatal
};
11
14
class
ARIA_RUNTIME_API
Logger
{
15
public
:
16
using
Sink
= std::function<void(
LogLevel
, std::string_view, std::string_view
/*message*/
)>;
17
19
static
Logger
&
instance
() noexcept;
20
21
Logger
(const
Logger
&) = delete;
22
Logger
& operator=(const
Logger
&) = delete;
23
Logger
(
Logger
&&) = delete;
24
Logger
& operator=(
Logger
&&) = delete;
25
26
void
set_sink
(
Sink
sink);
27
void
set_level
(
LogLevel
level
) noexcept;
28
[[nodiscard]]
LogLevel
level
() const noexcept;
29
32
void
log
(
LogLevel
level
,
std
::string_view category,
std
::string_view message) noexcept;
33
34
// Shorthands
35
void
trace
(
std
::string_view category,
std
::string_view m) {
log
(
LogLevel::Trace
, category, m); }
36
void
debug
(std::string_view category, std::string_view m) {
log
(
LogLevel::Debug
, category, m); }
37
void
info
(std::string_view category, std::string_view m) {
log
(
LogLevel::Info
, category, m); }
38
void
warn
(std::string_view category, std::string_view m) {
log
(
LogLevel::Warn
, category, m); }
39
void
error
(std::string_view category, std::string_view m) {
log
(
LogLevel::Error
, category, m); }
40
void
fatal
(std::string_view category, std::string_view m) {
log
(
LogLevel::Fatal
, category, m); }
41
42
private
:
43
Logger
();
44
~Logger
();
45
46
struct
Impl;
47
// RAII pImpl; C4251 on the unique_ptr member is a false positive for an
48
// incomplete opaque pointee consumed only via non-template API.
49
#ifdef _MSC_VER
50
# pragma warning(push)
51
# pragma warning(disable: 4251)
52
#endif
53
std::unique_ptr<Impl> impl_;
54
#ifdef _MSC_VER
55
# pragma warning(pop)
56
#endif
57
};
58
59
ARIA_RUNTIME_API
const
char
*
level_name
(
LogLevel
l)
noexcept
;
60
61
}
// namespace aria::runtime
aria::runtime::Logger
Process-wide logger.
Definition
logger.hpp:14
aria::runtime::Logger::instance
static Logger & instance() noexcept
Get the singleton (resolved from the runtime shared library, never duplicated).
aria::runtime::Logger::log
void log(LogLevel level, std::string_view category, std::string_view message) noexcept
Invoke the current sink without copying its captures.
aria::runtime::Logger::set_sink
void set_sink(Sink sink)
aria::runtime::Logger::set_level
void set_level(LogLevel level) noexcept
aria::runtime::Logger::trace
void trace(std::string_view category, std::string_view m)
Definition
logger.hpp:35
aria::runtime::Logger::error
void error(std::string_view category, std::string_view m)
Definition
logger.hpp:39
aria::runtime::Logger::level
LogLevel level() const noexcept
aria::runtime::Logger::debug
void debug(std::string_view category, std::string_view m)
Definition
logger.hpp:36
aria::runtime::Logger::Logger
Logger(const Logger &)=delete
aria::runtime::Logger::info
void info(std::string_view category, std::string_view m)
Definition
logger.hpp:37
aria::runtime::Logger::warn
void warn(std::string_view category, std::string_view m)
Definition
logger.hpp:38
aria::runtime::Logger::fatal
void fatal(std::string_view category, std::string_view m)
Definition
logger.hpp:40
aria::runtime::Logger::Sink
std::function< void(LogLevel, std::string_view, std::string_view)> Sink
Definition
logger.hpp:16
export.hpp
ARIA_RUNTIME_API
#define ARIA_RUNTIME_API
Definition
export.hpp:30
aria::runtime
Definition
container.hpp:11
aria::runtime::LogLevel
LogLevel
Definition
logger.hpp:10
aria::runtime::LogLevel::Info
@ Info
Definition
logger.hpp:10
aria::runtime::LogLevel::Warn
@ Warn
Definition
logger.hpp:10
aria::runtime::LogLevel::Fatal
@ Fatal
Definition
logger.hpp:10
aria::runtime::LogLevel::Error
@ Error
Definition
logger.hpp:10
aria::runtime::LogLevel::Debug
@ Debug
Definition
logger.hpp:10
aria::runtime::LogLevel::Trace
@ Trace
Definition
logger.hpp:10
aria::runtime::level_name
const char * level_name(LogLevel l) noexcept
std
Definition
validation_key.hpp:110
aria::Error
One uniform error record.
Definition
error.hpp:129
modules
runtime
include
aria
runtime
logger.hpp
Generated by
1.18.0