Botcraft 1.21.4
Loading...
Searching...
No Matches
Logger.hpp File Reference
#include <array>
#include <atomic>
#include <chrono>
#include <functional>
#include <mutex>
#include <sstream>
#include <string>
#include <string_view>
#include <thread>
#include <unordered_map>

Go to the source code of this file.

Classes

class  Botcraft::Logger
 

Namespaces

namespace  Botcraft
 

Macros

#define LOG(osstream, level)
 
#define LOG_TRACE(osstream)   LOG(osstream, Botcraft::LogLevel::Trace)
 
#define LOG_DEBUG(osstream)   LOG(osstream, Botcraft::LogLevel::Debug)
 
#define LOG_INFO(osstream)   LOG(osstream, Botcraft::LogLevel::Info)
 
#define LOG_WARNING(osstream)   LOG(osstream, Botcraft::LogLevel::Warning)
 
#define LOG_ERROR(osstream)   LOG(osstream, Botcraft::LogLevel::Error)
 
#define LOG_FATAL(osstream)   LOG(osstream, Botcraft::LogLevel::Fatal)
 

Enumerations

enum class  Botcraft::LogLevel {
  Botcraft::Trace , Botcraft::Debug , Botcraft::Info , Botcraft::Warning ,
  Botcraft::Error , Botcraft::Fatal , Botcraft::None , Botcraft::NUM_LOG_LEVEL
}
 

Functions

constexpr const char * file_name (const char *path)
 
std::ostream & Botcraft::operator<< (std::ostream &os, const LogLevel v)
 

Macro Definition Documentation

◆ LOG

#define LOG (   osstream,
  level 
)
Value:
do { \
if (level < logger.GetLogLevel()) \
break; \
std::ostringstream logger_ostringstream; \
logger_ostringstream << logger.GetDate().rdbuf() \
<< ' ' << Botcraft::Logger::level_strings[static_cast<size_t>(level)] \
<< " [" << logger.GetThreadName(std::this_thread::get_id()) \
<< "(" << std::this_thread::get_id() << ")] " \
<< file_name(__FILE__) << '(' << __LINE__ << "): " << osstream << '\n'; \
logger.Log(logger_ostringstream.str()); \
} while(0)
constexpr const char * file_name(const char *path)
Definition Logger.hpp:14
LogLevel GetLogLevel() const
Definition Logger.cpp:73
std::stringstream GetDate() const
Definition Logger.cpp:84
void Log(const std::string &s)
Definition Logger.cpp:42
static Logger & GetInstance()
Definition Logger.cpp:36
std::string GetThreadName(const std::thread::id id)
Get the name of a given thread.
Definition Logger.cpp:124
static constexpr std::array< std::string_view, static_cast< size_t >(LogLevel::NUM_LOG_LEVEL)> level_strings
Definition Logger.hpp:68

Definition at line 28 of file Logger.hpp.

◆ LOG_DEBUG

#define LOG_DEBUG (   osstream)    LOG(osstream, Botcraft::LogLevel::Debug)

Definition at line 42 of file Logger.hpp.

◆ LOG_ERROR

#define LOG_ERROR (   osstream)    LOG(osstream, Botcraft::LogLevel::Error)

Definition at line 45 of file Logger.hpp.

◆ LOG_FATAL

#define LOG_FATAL (   osstream)    LOG(osstream, Botcraft::LogLevel::Fatal)

Definition at line 46 of file Logger.hpp.

◆ LOG_INFO

#define LOG_INFO (   osstream)    LOG(osstream, Botcraft::LogLevel::Info)

Definition at line 43 of file Logger.hpp.

◆ LOG_TRACE

#define LOG_TRACE (   osstream)    LOG(osstream, Botcraft::LogLevel::Trace)

Definition at line 41 of file Logger.hpp.

◆ LOG_WARNING

#define LOG_WARNING (   osstream)    LOG(osstream, Botcraft::LogLevel::Warning)

Definition at line 44 of file Logger.hpp.

Function Documentation

◆ file_name()

constexpr const char * file_name ( const char *  path)
constexpr

Definition at line 14 of file Logger.hpp.