12#include <unordered_map>
16 const char* file = path;
19 if (*path ==
'\\' || *path ==
'/')
28#define LOG(osstream, level) do { \
29 Botcraft::Logger& logger = Botcraft::Logger::GetInstance(); \
30 if (level < logger.GetLogLevel()) \
32 std::ostringstream logger_ostringstream; \
33 logger_ostringstream << logger.GetDate().rdbuf() \
34 << ' ' << Botcraft::Logger::level_strings[static_cast<size_t>(level)] \
35 << " [" << logger.GetThreadName(std::this_thread::get_id()) \
36 << "(" << std::this_thread::get_id() << ")] " \
37 << file_name(__FILE__) << '(' << __LINE__ << "): " << osstream << '\n'; \
38 logger.Log(logger_ostringstream.str()); \
41#define LOG_TRACE(osstream) LOG(osstream, Botcraft::LogLevel::Trace)
42#define LOG_DEBUG(osstream) LOG(osstream, Botcraft::LogLevel::Debug)
43#define LOG_INFO(osstream) LOG(osstream, Botcraft::LogLevel::Info)
44#define LOG_WARNING(osstream) LOG(osstream, Botcraft::LogLevel::Warning)
45#define LOG_ERROR(osstream) LOG(osstream, Botcraft::LogLevel::Error)
46#define LOG_FATAL(osstream) LOG(osstream, Botcraft::LogLevel::Fatal)
85 void Log(
const std::string& s);
89 void SetLogFunc(
const std::function<
void(
const std::string&)>& f);
90 std::stringstream
GetDate()
const;
99 void RegisterThread(
const std::thread::id
id,
const std::string& name);
constexpr const char * file_name(const char *path)
void UnregisterThread(const std::thread::id id)
Remove a thread from the map.
std::atomic< LogLevel > log_level
void RegisterThread(const std::string &name)
Register the current thread in the map.
LogLevel GetLogLevel() const
std::stringstream GetDate() const
void Log(const std::string &s)
static Logger & GetInstance()
std::chrono::steady_clock::time_point last_time_logged
std::string GetThreadName(const std::thread::id id)
Get the name of a given thread.
void SetLogLevel(const LogLevel l)
std::unordered_map< std::thread::id, std::string > thread_names
Logger & operator=(Logger &&)=delete
Logger(const Logger &)=delete
std::function< void(const std::string &)> log_func
Logger & operator=(const Logger &)=delete
static constexpr std::array< std::string_view, static_cast< size_t >(LogLevel::NUM_LOG_LEVEL)> level_strings
void SetFilename(const std::string &s)
void SetLogFunc(const std::function< void(const std::string &)> &f)
std::ostream & operator<<(std::ostream &os, const EntityAttribute::Type v)