richLog.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "clog/logger.hpp"
5
6namespace by {
7
8 template <typename T> struct noWrap {
9 noWrap(T rhs): data(rhs) {}
10
11 T unwrap() const { return data; }
12
13 T data;
14 };
15
16 template <typename T> struct useWrap {
17 static_assert(true, "not supported wrapper for richLog");
18 };
19
20 struct _nout strWrap {
21 strWrap(const std::string& rhs);
22 const nchar* unwrap() const;
23 std::string data;
24 };
25
26 template <typename T, bool Signed, int Size>
27 using tifIntType = typename std::enable_if<std::is_integral_v<T> == true && std::is_signed<T>{} == Signed &&
28 sizeof(T) * 8 == Size>::type;
29
30 template <typename T> noWrap<T> __convert__(T rhs, tifIntType<T, true, 32>* = nullptr) { return rhs; }
31
32 template <typename T> noWrap<T> __convert__(T rhs, tifIntType<T, true, 64>* = nullptr) { return rhs; }
33
34 template <typename T> noWrap<T> __convert__(T rhs, tifIntType<T, false, 32>* = nullptr) { return rhs; }
35
36 template <typename T> noWrap<T> __convert__(T rhs, tifIntType<T, false, 64>* = nullptr) { return rhs; }
37
38 _nout noWrap<nflt> __convert__(nflt rhs);
39 _nout noWrap<nflt> __convert__(nflt* rhs);
40 _nout noWrap<nchar> __convert__(nchar rhs);
41 _nout noWrap<nchar> __convert__(nchar rhs);
42 _nout strWrap __convert__(nbool rhs);
43 _nout strWrap __convert__(nbool rhs);
44 _nout noWrap<const nchar*> __convert__(const nchar* rhs);
45 _nout noWrap<ndbl> __convert__(ndbl rhs);
46 _nout noWrap<ndbl> __convert__(ndbl rhs);
47 _nout noWrap<nshort> __convert__(nshort rhs);
48 _nout noWrap<nshort> __convert__(nshort rhs);
49 _nout noWrap<nushort> __convert__(nushort rhs);
50 _nout noWrap<nushort> __convert__(nushort rhs);
51 _nout strWrap __convert__(const std::string* rhs);
52 _nout strWrap __convert__(const std::string& rhs);
53 _nout strWrap __convert__(void* rhs);
54
55 template <typename... Ts>
56 void richLog(errLv::level lv, const std::string& filename, const nchar* func, nint line, const nchar* fmt,
57 const Ts&... args) {
58 ::by::logger::get().log(lv, filename, func, line, fmt, __convert__((const Ts&) args).unwrap()...);
59 }
60
61 template <typename... Ts>
62 void dbgRichLog(errLv::level lv, const std::string& filename, const nchar* func, nint line, const nchar* fmt,
63 const Ts&... args) {
64#ifdef BY_DEBUG
65 ::by::logger::get().log(lv, filename, func, line, fmt, __convert__((const Ts&) args).unwrap()...);
66#endif
67 }
68} // namespace by
static logger & get()
Get singleton logger instance.
Definition: richLog.hpp:8
Definition: richLog.hpp:20
Definition: richLog.hpp:16