-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogger.mpp
More file actions
73 lines (60 loc) · 2.05 KB
/
Logger.mpp
File metadata and controls
73 lines (60 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
module;
#include <cstdio>
export module CppUtils.Logger;
import std;
import CppUtils.String;
import CppUtils.Execution.EventQueue;
import CppUtils.Pattern.Multiton;
import CppUtils.Terminal.Size;
import CppUtils.Terminal.TextColor;
import CppUtils.Terminal.TextModifier;
import CppUtils.Chrono.Concept;
// Todo: log le datetime
// Todo: log le stacktrace ( https://en.cppreference.com/w/cpp/utility/stacktrace_entry )
export namespace CppUtils
{
template<String::Hasher loggerName>
inline auto configureLogger(Execution::EventQueue& eventQueue) -> void;
template<String::Hasher loggerName = Type::Hash{}>
struct Logger final
{
[[nodiscard]] static inline auto& eventQueue() noexcept
{
auto& eventQueue = Pattern::Multiton<Execution::EventQueue, loggerName>::get();
[[maybe_unused]] static auto _ = (configure(eventQueue), true);
return eventQueue;
}
static inline auto configure(Execution::EventQueue& eventQueue) -> void
{
configureLogger<loggerName>(eventQueue);
}
template<String::Hasher logType = Type::Hash{}, class... Args>
static inline auto emit(Args&&... args) -> void
{
eventQueue().template emit<logType>(std::forward<Args>(args)...);
}
template<class... Args>
static inline auto emit(Type::Hash logType, Args&&... args) -> void
{
eventQueue().emit(logType, std::forward<Args>(args)...);
}
template<String::Hasher logType = Type::Hash{}, class... Args>
static inline auto print(std::format_string<Args...> fmt, Args&&... args) -> void
{
emit<logType>(std::format(fmt, std::forward<Args>(args)...));
}
template<String::Hasher... logTypes>
static inline auto subscribe(auto&& function) -> void
{
eventQueue().template subscribe<logTypes...>(std::forward<decltype(function)>(function));
}
template<Chrono::Duration Duration = std::chrono::milliseconds>
static inline auto waitUntilFinished(Duration timeout = Duration::zero()) -> bool
{
return eventQueue().waitUntilFinished(timeout);
}
};
template<String::Hasher loggerName>
inline auto configureLogger(Execution::EventQueue&) -> void
{}
}