62 enum Level { kOff, kTrace, kDebug, kInfo, kWarn, kError };
65 virtual void Trace(
const std::string& msg,
66 const std::string& filename,
67 const std::string& function,
69 virtual void Debug(
const std::string& msg,
70 const std::string& filename,
71 const std::string& function,
73 virtual void Info(
const std::string& msg,
74 const std::string& filename,
75 const std::string& function,
77 virtual void Warn(
const std::string& msg,
78 const std::string& filename,
79 const std::string& function,
81 virtual void Error(
const std::string& msg,
82 const std::string& filename,
83 const std::string& function,
88 template <
class Head,
class... Tail>
89 void BuildFormat(Head&& head, Tail&&... tail) {
91 this->BuildFormat(std::forward<Tail>(tail)...);
94 template <
class FormatString,
class... Args>
95 std::string Format(FormatString fmt_str, Args&&... args) {
96 std::lock_guard<std::mutex> lg(fmt_mtx_);
97 fmt_ = boost::format(fmt_str);
98 this->BuildFormat(args...);
102 static inline std::string GetFileName(
const std::string& path) {
105 pos1 = path.rfind(
'\\');
106 if (pos1 != std::string::npos) {
107 return path.substr(pos1 + 1, path.size() - pos1 - 1);
110 pos1 = path.rfind(
'/');
111 if (pos1 != std::string::npos) {
112 return path.substr(pos1 + 1, path.size() - pos1 - 1);
119 static void SetSharedInstance(std::unique_ptr<Logger> logger);
120 static Logger* Shared();
124 static std::unique_ptr<Logger> shared_;