smgl 0.11.0
Structured Metadata Engine and Graph Objects Library
Loading...
Searching...
No Matches
LoggingPrivate.hpp
1#include <iomanip>
2#include <iostream>
3
4#include "smgl/Logging.hpp"
5#include "smgl/Singleton.hpp"
6#include "smgl/Utilities.hpp"
7
8namespace smgl
9{
10
11namespace detail
12{
13
15{
16private:
18 std::ostream* out_;
19
20public:
21 LoggingConfig() : out_{&std::cerr} { *out_ << std::boolalpha; }
22
23 [[nodiscard]] auto level() const -> LogLevel { return level_; }
24
25 void level(LogLevel level) { level_ = level; }
26
27 auto check(LogLevel msgLevel) -> bool { return msgLevel >= level_; }
28
29 auto out() -> std::ostream& { return *out_; }
30
31 void out(std::ostream* out) { out_ = out; }
32};
33
35
36template <typename T>
37void LogStart(const T& arg)
38{
39 LogConf::Instance().out() << arg;
40}
41
42template <typename T>
43void LogArg(const T& arg)
44{
45 LogConf::Instance().out() << ' ' << arg;
46}
47
48template <typename... Args>
49void LogMessage(Args... args)
50{
51#if __cplusplus >= 201703L
52 (detail::LogArg(args), ...);
53#elif __cplusplus > 201103L
54 detail::ExpandType{0, (detail::LogArg(std::forward<Args>(args)), 0)...};
55#endif
57}
58} // namespace detail
59
60template <typename... Args>
61void LogError(Args... args)
62{
64 return;
65 }
66
67 detail::LogStart("[smgl] [error]");
68 detail::LogMessage(std::forward<Args>(args)...);
69}
70
71template <typename... Args>
72void LogWarning(Args... args)
73{
75 return;
76 }
77
78 detail::LogStart("[smgl] [warning]");
79 detail::LogMessage(std::forward<Args>(args)...);
80}
81
82template <typename... Args>
83void LogInfo(Args... args)
84{
86 return;
87 }
88
89 detail::LogStart("[smgl] [info]");
90 detail::LogMessage(std::forward<Args>(args)...);
91}
92
93template <typename... Args>
94void LogDebug(Args... args)
95{
97 return;
98 }
99
100 detail::LogStart("[smgl] [debug]");
101 detail::LogMessage(std::forward<Args>(args)...);
102}
103
104} // namespace smgl
Library logging utilities.
T boolalpha(T... args)
Class for constructing and managing the lifetime of a singleton object.
static T & Instance()
Access the singleton instance.
T endl(T... args)
T make_shared(T... args)
Project top-level namespace.
LogLevel
Log levels.
Definition Logging.hpp:18
@ None
No messages.
Definition Logging.hpp:24
@ Warning
Warning messages and above.
Definition Logging.hpp:22
@ Debug
Debug messages and above.
Definition Logging.hpp:20
@ Error
Error messages and above.
Definition Logging.hpp:23
@ Info
Info messages and above.
Definition Logging.hpp:21