spdlog/include/spdlog/common.h

59 lines
984 B
C
Raw Normal View History

#pragma once
#include<initializer_list>
#include<chrono>
2014-10-31 07:13:27 +08:00
namespace spdlog
{
class formatter;
2014-11-01 08:28:49 +08:00
namespace sinks
{
class sink;
}
// Common types across the lib
using log_clock = std::chrono::system_clock;
using sink_ptr = std::shared_ptr < sinks::sink > ;
using sinks_init_list = std::initializer_list < sink_ptr > ;
2014-10-31 07:13:27 +08:00
using formatter_ptr = std::shared_ptr<spdlog::formatter>;
//Log level enum
namespace level
{
typedef enum
{
TRACE,
DEBUG,
INFO,
2014-10-24 23:01:11 +08:00
WARN,
ERR,
CRITICAL,
2014-10-31 07:13:27 +08:00
ALWAYS,
OFF
} level_enum;
2014-10-31 07:13:27 +08:00
static const char* level_names[] { "trace", "debug", "info", "warning", "error", "critical", "", ""};
inline const char* to_str(spdlog::level::level_enum l)
{
return level_names[l];
}
} //level
2014-10-26 07:29:50 +08:00
//
// Log exception
//
class spdlog_ex : public std::exception
2014-10-26 07:29:50 +08:00
{
public:
spdlog_ex(const std::string& msg) :_msg(msg) {};
2014-11-01 08:28:49 +08:00
const char* what() const throw() override
{
2014-10-26 07:29:50 +08:00
return _msg.c_str();
}
private:
std::string _msg;
};
2014-10-31 07:13:27 +08:00
} //spdlog