-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathlogger.h
76 lines (69 loc) · 2.1 KB
/
logger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#include <exception>
#ifndef DISABLE_SPDLOG
#include <spdlog/spdlog.h>
#endif
#include <string_view>
namespace coacd
{
namespace logger
{
#ifndef DISABLE_SPDLOG
std::shared_ptr<spdlog::logger> get();
#else
template <typename Arg, typename... Args>
void doPrint(std::ostream& out, Arg&& arg, Args&&... args)
{
out << std::forward<Arg>(arg);
using expander = int[];
(void)expander{0, (void(out << ',' << std::forward<Args>(args)), 0)...};
out << std::endl;
}
#endif
template <typename... Args>
inline void debug(std::string_view fmt, const Args &...args)
{
#ifndef DISABLE_SPDLOG
get()->debug(fmt, args...);
#else
doPrint(std::cout, fmt, args...);
#endif
};
template <typename... Args>
inline void info(std::string_view fmt, const Args &...args)
{
#ifndef DISABLE_SPDLOG
get()->info(fmt, args...);
#else
doPrint(std::cout, fmt, args...);
#endif
};
template <typename... Args>
inline void warn(std::string_view fmt, const Args &...args)
{
#ifndef DISABLE_SPDLOG
get()->warn(fmt, args...);
#else
doPrint(std::cout, fmt, args...);
#endif
};
template <typename... Args>
inline void error(std::string_view fmt, const Args &...args)
{
#ifndef DISABLE_SPDLOG
get()->error(fmt, args...);
#else
doPrint(std::cout, fmt, args...);
#endif
};
template <typename... Args>
inline void critical(std::string_view fmt, const Args &...args)
{
#ifndef DISABLE_SPDLOG
get()->critical(fmt, args...);
#else
doPrint(std::cout, fmt, args...);
#endif
};
} // namespace logger
} // namespace coacd