Tramway SDK
logging.h
Go to the documentation of this file.
1// TRAMWAY DRIFT AND DUNGEON EXPLORATION SIMULATOR 2022
2// All rights reserved.
3
4#ifndef TRAM_SDK_FRAMEWORK_LOGGING_H
5#define TRAM_SDK_FRAMEWORK_LOGGING_H
6
7#include <framework/core.h>
8#include <framework/uid.h>
9#include <framework/system.h>
10#include <concepts>
11
12namespace tram {
13
14namespace implementation {
15 template <typename T> void concat (const T& value) {
16 concat<const char*> ("LOGGER_UNDEFINED_TYPE");
17 }
18
19 template <> void concat(const std::string_view& value);
20 template <> void concat(const std::string& value);
21 template <> void concat(const char* const& value);
22 template <> void concat(const UID& value);
23
24 template <typename T> void concat_numeric(const T& value) {}
25 template <> void concat_numeric(const int64_t& value);
26 template <> void concat_numeric(const uint64_t& value);
27 template <> void concat_numeric(const float& value);
28
29 template <std::signed_integral T> void concat(const T& value) {
30 concat_numeric<int64_t>(value);
31 }
32
33 template <std::unsigned_integral T> void concat(const T& value) {
34 concat_numeric<uint64_t>(value);
35 }
36
37 template <std::floating_point T> void concat(const T& value) {
38 concat_numeric<float>(value);
39 }
40
41 void concat_fmt(std::string_view& str);
42 void flush_console(int severity, int system);
43 void flush_callback(int severity, int system);
44
45
46 inline void log(void(*flush)(int, int), int severity, int system, std::string_view& format) {
47 concat_fmt(format);
48 flush(severity, system);
49 }
50
51 template <typename T, typename... Args>
52 void log(void(*flush)(int, int), int severity, int system, std::string_view& format, T value, Args&&... args) {
53 concat_fmt(format);
54 concat<T>(value);
55
56 log(flush, severity, system, format, args...);
57 }
58}
59
66};
67
68void SetSystemLoggingSeverity(System::system_t system, Severity min_severity);
69
70void SetLogCallback(void(int, const char*));
71
72template <typename... Args>
73void Log(int severity, int system, const std::string_view& format, Args&&... args) {
74 std::string_view format_view = format;
75 implementation::log(implementation::flush_console, severity, system, format_view, args...);
76}
77
78template <typename... Args>
79void Log(int system, const std::string_view& format, Args&&... args) {
80 std::string_view format_view = format;
81 implementation::log(implementation::flush_console, 0, system, format_view, args...);
82}
83
84template <typename... Args>
85void Log(const std::string_view& format, Args&&... args) {
86 std::string_view format_view = format;
87 implementation::log(implementation::flush_console, 0, 6, format_view, args...);
88}
89
90template <typename... Args>
91void DisplayLog(int time, const std::string_view& format, Args&&... args) {
92 std::string_view format_view = format;
93 implementation::log(implementation::flush_callback, time, 6, format_view, args...);
94}
95
96}
97
98#endif // TRAM_SDK_LOGGING_H
uint32_t system_t
Definition: system.h:11
void flush_console(int severity, int system)
Definition: logging.cpp:49
void concat_fmt(std::string_view &str)
Definition: logging.cpp:37
void concat(const std::string_view &value)
Definition: logging.cpp:84
void flush_callback(int severity, int system)
Definition: logging.cpp:76
void concat_numeric(const int64_t &value)
Definition: logging.cpp:106
void log(void(*flush)(int, int), int severity, int system, std::string_view &format)
Definition: logging.h:46
Definition: api.h:9
Severity
Definition: logging.h:60
@ SEVERITY_CRITICAL_ERROR
Definition: logging.h:64
@ SEVERITY_WARNING
Definition: logging.h:62
@ SEVERITY_ERROR
Definition: logging.h:63
@ SEVERITY_INFO
Definition: logging.h:61
@ SEVERITY_DEFAULT
Definition: logging.h:65
void Log(int severity, int system, const std::string_view &format, Args &&... args)
Definition: logging.h:73
void SetLogCallback(void(*callback)(int, const char *))
Definition: logging.cpp:25
void DisplayLog(int time, const std::string_view &format, Args &&... args)
Definition: logging.h:91
void SetSystemLoggingSeverity(System::system_t system, Severity min_severity)
Definition: logging.cpp:15
Definition: uid.h:11