Loading...
Searching...
No Matches
richLog.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "clog/logger.hpp"
5
6namespace by {
7
34 template <typename T> struct noWrap {
35 noWrap(T rhs): data(rhs) {}
36
37 T unwrap() const { return data; }
38
39 T data;
40 };
41
42 template <typename T> struct useWrap {
43 static_assert(true, "not supported wrapper for richLog");
44 };
45
46 struct _nout strWrap {
47 strWrap(const std::string& rhs);
48 const nchar* unwrap() const;
49 std::string data;
50 };
51
52 template <typename T, bool Signed, int Size>
53 using tifIntType = typename std::enable_if<std::is_integral_v<T> == true && std::is_signed<T>{} == Signed &&
54 sizeof(T) * 8 == Size>::type;
55
56 template <typename T> noWrap<T> __convert__(T rhs, tifIntType<T, true, 32>* = nullptr) { return rhs; }
57
58 template <typename T> noWrap<T> __convert__(T rhs, tifIntType<T, true, 64>* = nullptr) { return rhs; }
59
60 template <typename T> noWrap<T> __convert__(T rhs, tifIntType<T, false, 32>* = nullptr) { return rhs; }
61
62 template <typename T> noWrap<T> __convert__(T rhs, tifIntType<T, false, 64>* = nullptr) { return rhs; }
63
64 _nout noWrap<nflt> __convert__(nflt rhs);
65 _nout noWrap<nflt> __convert__(nflt* rhs);
66 _nout noWrap<nchar> __convert__(nchar rhs);
67 _nout noWrap<const nchar*> __convert__(nchar* rhs);
68 _nout noWrap<const nchar*> __convert__(const nchar* rhs);
69 _nout strWrap __convert__(nbool rhs);
70 _nout strWrap __convert__(nbool* rhs);
71 _nout noWrap<ndbl> __convert__(ndbl rhs);
72 _nout noWrap<ndbl> __convert__(ndbl* rhs);
73 _nout noWrap<nshort> __convert__(nshort rhs);
74 _nout noWrap<nshort> __convert__(nshort* rhs);
75 _nout noWrap<nushort> __convert__(nushort rhs);
76 _nout noWrap<nushort> __convert__(nushort* rhs);
77 _nout strWrap __convert__(const std::string* rhs);
78 _nout strWrap __convert__(const std::string& rhs);
79 _nout strWrap __convert__(void* rhs);
80
81 template <typename... Ts>
82 void richLog(errLv::level lv, const std::string& filename, const nchar* func, nint line, const nchar* fmt,
83 const Ts&... args) {
84 ::by::logger::get().log(lv, filename, func, line, fmt, __convert__((const Ts&) args).unwrap()...);
85 }
86
87 template <typename... Ts>
88 void dbgRichLog(errLv::level lv, const std::string& filename, const nchar* func, nint line, const nchar* fmt,
89 const Ts&... args) {
90#ifdef BY_DEBUG
91 ::by::logger::get().log(lv, filename, func, line, fmt, __convert__((const Ts&) args).unwrap()...);
92#endif
93 }
94} // namespace by
static logger & get()
Get singleton logger instance.
Rich logging support with polymorphic type conversion.
Definition richLog.hpp:34
Definition richLog.hpp:46
Definition richLog.hpp:42