libcryfs/src/cpp-utils/logging/logging.h

77 lines
1.9 KiB
C
Raw Normal View History

2015-10-17 03:08:56 +02:00
#pragma once
#ifndef MESSMER_CPPUTILS_LOGGING_LOGGING_H
#define MESSMER_CPPUTILS_LOGGING_LOGGING_H
#include "Logger.h"
#include <stdexcept>
2017-02-04 20:03:20 +01:00
#include <spdlog/fmt/ostr.h>
2018-08-08 03:27:34 +02:00
2015-10-17 03:08:56 +02:00
namespace cpputils {
namespace logging {
struct ERROR_TYPE {};
struct WARN_TYPE {};
struct INFO_TYPE {};
struct DEBUG_TYPE {};
2018-05-19 07:29:52 +02:00
constexpr ERROR_TYPE ERR {};
constexpr WARN_TYPE WARN {};
constexpr INFO_TYPE INFO {};
constexpr DEBUG_TYPE DEBUG {};
2015-10-17 03:08:56 +02:00
inline void setLogger(std::shared_ptr<spdlog::logger> newLogger) {
logger().setLogger(newLogger);
}
2015-10-17 15:49:54 +02:00
inline void reset() {
logger().reset();
}
2021-12-11 11:15:40 +01:00
inline void flush() {
logger()->flush();
}
inline void setLevel(ERROR_TYPE) {
logger().setLevel(spdlog::level::err);
}
inline void setLevel(WARN_TYPE) {
logger().setLevel(spdlog::level::warn);
}
inline void setLevel(INFO_TYPE) {
logger().setLevel(spdlog::level::info);
}
inline void setLevel(DEBUG_TYPE) {
logger().setLevel(spdlog::level::debug);
}
2017-02-04 20:03:20 +01:00
template<class LogType> inline void LOG(LogType logType, const std::string &msg) {
LOG(logType, msg.c_str());
}
2017-02-04 20:03:20 +01:00
template <typename... Args>
inline void LOG(ERROR_TYPE, const char* fmt, const Args&... args) {
logger()->error(fmt, args...);
}
2017-02-04 20:03:20 +01:00
template <typename... Args>
inline void LOG(WARN_TYPE, const char* fmt, const Args&... args) {
logger()->warn(fmt, args...);
}
2017-02-04 20:03:20 +01:00
template <typename... Args>
inline void LOG(INFO_TYPE, const char* fmt, const Args&... args) {
logger()->info(fmt, args...);
}
template <typename... Args>
inline void LOG(DEBUG_TYPE, const char* fmt, const Args&... args) {
logger()->debug(fmt, args...);
2015-10-17 03:08:56 +02:00
}
}
}
#endif