BioCMAMC-ST
logger.hpp
1#ifndef __COMMON_LOGGER_HPP__
2#define __COMMON_LOGGER_HPP__
3
4#include <source_location>
5#include <string>
6#include <string_view>
7
8namespace IO
9{
10
11 namespace AnsiCode
12 {
13 constexpr auto blue = "\033[34m";
14 constexpr auto red = "\033[31m";
15 constexpr auto reset = "\033[0m";
16 constexpr auto green = "\033[32m";
17 } // namespace AnsiCode
18
19 namespace Unicode
20 {
21 constexpr auto red_circle = "\U0001F534";
22 } // namespace Unicode
23
29 class Logger
30 {
31 public:
32 Logger() = default;
33 Logger(const Logger&) = default;
34 Logger(Logger&&) = default;
35 Logger& operator=(const Logger&) = default;
36 Logger& operator=(Logger&&) = default;
37 virtual ~Logger() = default;
38
46 virtual void debug(std::string_view message) = 0;
47
57 virtual void print(std::string_view prefix, std::string_view message) = 0;
58
67 virtual void alert(std::string_view prefix, std::string_view message) = 0;
68
79 virtual void error(std::string_view message,
80 std::source_location location
81 = std::source_location::current())
82 = 0;
83
91 virtual void raw_log(std::string_view message) = 0;
92
98 virtual void toggle_debug() noexcept = 0;
99
105 virtual void toggle_print() noexcept = 0;
106
112 virtual void toggle_alert() noexcept = 0;
113
119 virtual void toggle_error() noexcept = 0;
120
127 virtual void toggle_all() noexcept = 0;
128 };
129
130 template <typename... MsgType>
131 std::string
132 format(MsgType&&... msgs)
133 {
134 std::string result;
135 (result += ... += std::forward<MsgType>(msgs));
136 return result;
137 }
138
139} // namespace IO
140
141#endif
virtual void error(std::string_view message, std::source_location location=std::source_location::current())=0
Log an error message with optional location details.
Logger & operator=(const Logger &)=default
virtual void toggle_alert() noexcept=0
Toggle the alert logging behavior on or off.
virtual void toggle_debug() noexcept=0
Toggle the debug logging behavior on or off.
virtual void toggle_error() noexcept=0
Toggle the error logging behavior on or off.
virtual void raw_log(std::string_view message)=0
Log a raw message with no additional formatting.
virtual void debug(std::string_view message)=0
Log a debug message.
Logger(const Logger &)=default
virtual ~Logger()=default
virtual void alert(std::string_view prefix, std::string_view message)=0
Log an alert message with a prefix.
Logger()=default
Logger & operator=(Logger &&)=default
virtual void print(std::string_view prefix, std::string_view message)=0
Log a regular print message with a prefix.
virtual void toggle_print() noexcept=0
Toggle the print logging behavior on or off.
virtual void toggle_all() noexcept=0
Toggle all logging types on or off.
Logger(Logger &&)=default
Definition logger.hpp:12
constexpr auto red
Definition logger.hpp:14
constexpr auto green
Definition logger.hpp:16
constexpr auto reset
Definition logger.hpp:15
constexpr auto blue
Definition logger.hpp:13
Definition logger.hpp:20
constexpr auto red_circle
Definition logger.hpp:21
Definition impl_post_process.hpp:11
std::string format(MsgType &&... msgs)
Definition logger.hpp:132