Tramway SDK
logging.h
Go to the documentation of this file.
1// Tramway Drifting and Dungeon Exploration Simulator SDK Runtime
2
3#ifndef TRAM_SDK_FRAMEWORK_LOGGING_H
4#define TRAM_SDK_FRAMEWORK_LOGGING_H
5
6#include <framework/core.h>
7#include <framework/uid.h>
8#include <framework/system.h>
9#include <concepts>
10
11namespace tram {
12
13enum class Severity {
14 INFO, //< For debugging and other verbose messages. Not printed by default.
15 WARNING, //< For errors that are corrected and require no end-user intervention.
16 ERROR, //< For significant erros that can be corrected, but require the end-user to be notified.
17 CRITICAL_ERROR, //< For errors that cannot be recovered from.
18 DEFAULT //< Informational messages, always printed.
19};
20
21namespace implementation {
22 template <typename T> void concat(const T& value) {
23 concat<const char*>("LOGGER_UNDEFINED_TYPE");
24 }
25
26 template <> void concat(const std::string_view& value);
27 template <> void concat(const std::string& value);
28 template <> void concat(const char* const& value);
29 template <> void concat(const UID& value);
30 template <size_t N>
31 void concat(const char (&value)[N]) {
32 concat<const char*>(value);
33 }
34
35 void concat(const char*);
36
37 template <typename T> void concat_numeric(const T& value) {}
38 template <> void concat_numeric(const int64_t& value);
39 template <> void concat_numeric(const uint64_t& value);
40 template <> void concat_numeric(const float& value);
41
42 template <std::signed_integral T> void concat(const T& value) {
43 concat_numeric<int64_t>(value);
44 }
45
46 template <std::unsigned_integral T> void concat(const T& value) {
47 concat_numeric<uint64_t>(value);
48 }
49
50 template <std::floating_point T> void concat(const T& value) {
51 concat_numeric<float>(value);
52 }
53
54 void concat_fmt(std::string_view& str);
55 void flush_console(Severity severity, System::system_t system);
56 void flush_display(int time, System::system_t system);
57
58
59 inline void log(void(*flush)(Severity, System::system_t), Severity severity, System::system_t system, std::string_view& format) {
60 concat_fmt(format);
61 flush(severity, system);
62 }
63
64 template <typename T, typename... Args>
65 void log(void(*flush)(Severity, System::system_t), Severity severity, System::system_t system, std::string_view& format, T& value, Args&&... args) {
66 concat_fmt(format);
67 concat(value);
68
69 log(flush, severity, system, format, args...);
70 }
71}
72
73void SetSystemLoggingSeverity(System::system_t system, Severity min_severity);
74
75void SetDisplayLogCallback(void(int, const char*));
76void SetConsoleLogCallback(void(int, const char*));
77
78template <typename... Args>
79void Log(Severity severity, System::system_t system, const std::string_view& format, Args&&... args) {
80 std::string_view format_view = format;
81 implementation::log(implementation::flush_console, severity, system, format_view, args...);
82}
83
84template <typename... Args>
85void Log(System::system_t system, const std::string_view& format, Args&&... args) {
86 std::string_view format_view = format;
88}
89
90template <typename... Args>
91void Log(const std::string_view& format, Args&&... args) {
92 std::string_view format_view = format;
94}
95
96template <typename... Args>
97void DisplayLog(int time, const std::string_view& format, Args&&... args) {
98 std::string_view format_view = format;
99 implementation::log(implementation::flush_display, time, 6, format_view, args...);
100}
101
102}
103
104#endif // TRAM_SDK_LOGGING_H
uint32_t system_t
Definition: system.h:10
void concat_fmt(std::string_view &str)
Definition: logging.cpp:62
void flush_console(Severity severity, System::system_t system)
Definition: logging.cpp:74
void concat(const std::string_view &value)
Definition: logging.cpp:134
void log(void(*flush)(Severity, System::system_t), Severity severity, System::system_t system, std::string_view &format)
Definition: logging.h:59
void concat_numeric(const int64_t &value)
Definition: logging.cpp:161
void flush_display(int time, int system)
Definition: logging.cpp:126
Serialization, i.e.
Severity
Definition: logging.h:13
void Log(Severity severity, System::system_t system, const std::string_view &format, Args &&... args)
Definition: logging.h:79
void DisplayLog(int time, const std::string_view &format, Args &&... args)
Definition: logging.h:97
void SetSystemLoggingSeverity(System::system_t system, Severity min_severity)
Sets the logging severity filter.
Definition: logging.cpp:27
void SetConsoleLogCallback(void(*callback)(int, const char *))
Sets the console log callback.
Definition: logging.cpp:48
void SetDisplayLogCallback(void(*callback)(int, const char *))
Sets the display log callback.
Definition: logging.cpp:41
Interned string type.
Definition: uid.h:10