34 return static_cast<std::underlying_type_t<E>
>(e);
54 template <
typename Func>
static void logExecutionTime(
const std::string &message, Func &&func)
56 const auto start = std::chrono::high_resolution_clock::now();
58 const auto end = std::chrono::high_resolution_clock::now();
59 const auto duration = std::chrono::duration<float, std::milli>(end - start).count();
71 static void log(
const std::string &message,
const LogLevel &logLevel)
109 using namespace std::chrono;
111 const auto now = system_clock::now();
112 const auto inTimeT = system_clock::to_time_t(now);
113 const auto ms = duration_cast<milliseconds>(now.time_since_epoch()) % 1000;
115 std::ostringstream ss;
116 ss <<
"[" << std::put_time(std::localtime(&inTimeT),
"%Y-%m-%d %H:%M:%S");
117 ss <<
":" << std::setfill(
'0') << std::setw(3) << ms.count() <<
"] ";
118 ss <<
"[" <<
LOG_LEVEL_STRING[
static_cast<uint8_t
>(level)] <<
"] " << message;
Logger & operator=(const Logger &)=delete
Logger & operator=(Logger &&)=delete
static constexpr std::array< const char *, 2 > LOG_LEVEL_STRING
static constexpr auto to_underlying(E e) noexcept
static constexpr std::array< const char *, 4 > LOG_LEVEL_COLOR
static std::string formatLogMessage(LogLevel level, const std::string &message)
static void init()
Initialize the logger.
Logger(const Logger &)=delete
static void log(const std::string &message, const LogLevel &logLevel)
Log a message with a specific log level.
static void logExecutionTime(const std::string &message, Func &&func)
Log the execution time of a function.
static const char * getColorForDuration(const float duration)