66 enum Level { kOff, kTrace, kDebug, kInfo, kWarn, kError };
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_;