SILICON
Loading...
Searching...
No Matches
logger.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <functional>
5#include <string>
6#include <string_view>
7
8namespace SILICON::logging {
9
18
19struct LogMessage {
21 std::string category;
22 std::string message;
23 std::string formatted;
24};
25
26class Logger {
27public:
28 using SinkHandle = std::size_t;
29 using CallbackSink = std::function<void(const LogMessage&)>;
30
31 explicit Logger(std::string category);
32
33 static void initialize();
34 static void shutdown();
35 static void addConsoleSink(std::ostream& stream);
36 static void setMinimumLevel(LogLevel level);
38 static void removeSink(SinkHandle handle);
39
40 static void trace(std::string_view category, std::string_view message);
41 static void debug(std::string_view category, std::string_view message);
42 static void info(std::string_view category, std::string_view message);
43 static void warning(std::string_view category, std::string_view message);
44 static void error(std::string_view category, std::string_view message);
45 static void critical(std::string_view category, std::string_view message);
46
47 void trace(std::string_view message) const;
48 void debug(std::string_view message) const;
49 void info(std::string_view message) const;
50 void warning(std::string_view message) const;
51 void error(std::string_view message) const;
52 void critical(std::string_view message) const;
53
54private:
55 std::string category;
56
57 static void log(LogLevel level, std::string_view category, std::string_view message);
58};
59
60} // namespace SILICON::logging
static void error(std::string_view category, std::string_view message)
Definition logger.cpp:292
static void initialize()
Definition logger.cpp:180
static SinkHandle addCallbackSink(CallbackSink callback)
Definition logger.cpp:240
static void setMinimumLevel(LogLevel level)
Definition logger.cpp:231
std::size_t SinkHandle
Definition logger.hpp:28
static void removeSink(SinkHandle handle)
Definition logger.cpp:258
static void warning(std::string_view category, std::string_view message)
Definition logger.cpp:287
static void trace(std::string_view category, std::string_view message)
Definition logger.cpp:272
static void shutdown()
Definition logger.cpp:187
static void critical(std::string_view category, std::string_view message)
Definition logger.cpp:297
Logger(std::string category)
Definition logger.cpp:178
static void debug(std::string_view category, std::string_view message)
Definition logger.cpp:277
static void info(std::string_view category, std::string_view message)
Definition logger.cpp:282
std::function< void(const LogMessage &)> CallbackSink
Definition logger.hpp:29
static void addConsoleSink(std::ostream &stream)
Definition logger.cpp:208
static void log(LogLevel level, std::string_view category, std::string_view message)
Definition logger.cpp:332