9 #ifndef SKYWAY_GLOBAL_INTERFACE_LOGGER_HPP_
10 #define SKYWAY_GLOBAL_INTERFACE_LOGGER_HPP_
12 #include <boost/format.hpp>
16 #define __SKW_FILE__ skyway::global::interface::Logger::GetFileName(__FILE__)
18 #define SKW_TRACE(msg, ...) \
19 if (skyway::global::interface::Logger::Shared()) { \
20 std::string formatted = \
21 skyway::global::interface::Logger::Shared()->Format(msg, ##__VA_ARGS__); \
22 skyway::global::interface::Logger::Shared()->Trace( \
23 formatted, __SKW_FILE__, __FUNCTION__, __LINE__); \
26 #define SKW_DEBUG(msg, ...) \
27 if (skyway::global::interface::Logger::Shared()) { \
28 std::string formatted = \
29 skyway::global::interface::Logger::Shared()->Format(msg, ##__VA_ARGS__); \
30 skyway::global::interface::Logger::Shared()->Debug( \
31 formatted, __SKW_FILE__, __FUNCTION__, __LINE__); \
34 #define SKW_INFO(msg, ...) \
35 if (skyway::global::interface::Logger::Shared()) { \
36 std::string formatted = \
37 skyway::global::interface::Logger::Shared()->Format(msg, ##__VA_ARGS__); \
38 skyway::global::interface::Logger::Shared()->Info( \
39 formatted, __SKW_FILE__, __FUNCTION__, __LINE__); \
42 #define SKW_WARN(msg, ...) \
43 if (skyway::global::interface::Logger::Shared()) { \
44 std::string formatted = \
45 skyway::global::interface::Logger::Shared()->Format(msg, ##__VA_ARGS__); \
46 skyway::global::interface::Logger::Shared()->Warn( \
47 formatted, __SKW_FILE__, __FUNCTION__, __LINE__); \
50 #define SKW_ERROR(msg, ...) \
51 if (skyway::global::interface::Logger::Shared()) { \
52 std::string formatted = \
53 skyway::global::interface::Logger::Shared()->Format(msg, ##__VA_ARGS__); \
54 skyway::global::interface::Logger::Shared()->Error( \
55 formatted, __SKW_FILE__, __FUNCTION__, __LINE__); \
66 enum Level { kOff, kTrace, kDebug, kInfo, kWarn, kError };
68 virtual ~
Logger() =
default;
69 virtual void Trace(
const std::string& msg,
70 const std::string& filename,
71 const std::string&
function,
73 virtual void Debug(
const std::string& msg,
74 const std::string& filename,
75 const std::string&
function,
77 virtual void Info(
const std::string& msg,
78 const std::string& filename,
79 const std::string&
function,
81 virtual void Warn(
const std::string& msg,
82 const std::string& filename,
83 const std::string&
function,
85 virtual void Error(
const std::string& msg,
86 const std::string& filename,
87 const std::string&
function,
92 template <
class Head,
class... Tail>
93 void BuildFormat(Head&& head, Tail&&... tail) {
95 this->BuildFormat(std::forward<Tail>(tail)...);
98 template <
class FormatString,
class... Args>
99 std::string Format(FormatString fmt_str, Args&&... args) {
100 std::lock_guard<std::mutex> lg(fmt_mtx_);
101 fmt_ = boost::format(fmt_str);
102 this->BuildFormat(args...);
106 static inline std::string GetFileName(
const std::string& path) {
109 pos1 = path.rfind(
'\\');
110 if (pos1 != std::string::npos) {
111 return path.substr(pos1 + 1, path.size() - pos1 - 1);
114 pos1 = path.rfind(
'/');
115 if (pos1 != std::string::npos) {
116 return path.substr(pos1 + 1, path.size() - pos1 - 1);
123 static void SetSharedInstance(std::unique_ptr<Logger> logger);
124 static Logger* Shared();
128 static std::unique_ptr<Logger> shared_;
SkyWayのログを処理するクラス
Definition: logger.hpp:63
Level
ログレベル
Definition: logger.hpp:66
SkyWayで発生したエラーを示す構造体
Definition: error.hpp:18