2016-08-22 20:54:18 +03:00
|
|
|
//
|
|
|
|
// Copyright(c) 2015 Gabi Melman.
|
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-02-23 14:39:41 +02:00
|
|
|
#define SPDLOG_VERSION "0.16.3"
|
|
|
|
|
2018-02-23 14:34:25 +02:00
|
|
|
#include "tweakme.h"
|
|
|
|
|
2016-08-22 20:54:18 +03:00
|
|
|
#include <string>
|
|
|
|
#include <initializer_list>
|
|
|
|
#include <chrono>
|
|
|
|
#include <memory>
|
|
|
|
#include <atomic>
|
|
|
|
#include <exception>
|
|
|
|
#include<functional>
|
|
|
|
|
|
|
|
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
|
|
|
#include <codecvt>
|
|
|
|
#include <locale>
|
|
|
|
#endif
|
|
|
|
|
2017-11-11 13:44:27 +01:00
|
|
|
#include "details/null_mutex.h"
|
2016-08-22 20:54:18 +03:00
|
|
|
|
|
|
|
//visual studio upto 2013 does not support noexcept nor constexpr
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
|
|
|
#define SPDLOG_NOEXCEPT throw()
|
|
|
|
#define SPDLOG_CONSTEXPR
|
|
|
|
#else
|
|
|
|
#define SPDLOG_NOEXCEPT noexcept
|
|
|
|
#define SPDLOG_CONSTEXPR constexpr
|
|
|
|
#endif
|
|
|
|
|
2017-11-25 15:53:35 +02:00
|
|
|
// final keyword support. On by default. See tweakme.h
|
|
|
|
#if defined(SPDLOG_NO_FINAL)
|
2017-04-28 17:24:55 +02:00
|
|
|
#define SPDLOG_FINAL
|
2017-11-25 15:53:35 +02:00
|
|
|
#else
|
|
|
|
#define SPDLOG_FINAL final
|
2017-04-28 17:24:55 +02:00
|
|
|
#endif
|
|
|
|
|
2016-08-22 20:54:18 +03:00
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
2016-11-14 14:58:10 +02:00
|
|
|
#define SPDLOG_DEPRECATED __attribute__((deprecated))
|
2016-08-22 20:54:18 +03:00
|
|
|
#elif defined(_MSC_VER)
|
2016-11-14 14:58:10 +02:00
|
|
|
#define SPDLOG_DEPRECATED __declspec(deprecated)
|
2016-08-22 20:54:18 +03:00
|
|
|
#else
|
2016-11-14 14:58:10 +02:00
|
|
|
#define SPDLOG_DEPRECATED
|
2016-08-22 20:54:18 +03:00
|
|
|
#endif
|
|
|
|
|
2017-11-11 13:44:27 +01:00
|
|
|
#include "fmt/fmt.h"
|
2016-08-22 20:54:18 +03:00
|
|
|
|
|
|
|
namespace spdlog
|
|
|
|
{
|
|
|
|
|
|
|
|
class formatter;
|
|
|
|
|
2018-01-24 23:08:46 -02:00
|
|
|
template<class T, size_t N>
|
|
|
|
constexpr size_t size(T(&)[N]) { return N; }
|
|
|
|
|
2016-08-22 20:54:18 +03:00
|
|
|
namespace sinks
|
|
|
|
{
|
|
|
|
class sink;
|
|
|
|
}
|
|
|
|
|
|
|
|
using log_clock = std::chrono::system_clock;
|
|
|
|
using sink_ptr = std::shared_ptr < sinks::sink >;
|
|
|
|
using sinks_init_list = std::initializer_list < sink_ptr >;
|
|
|
|
using formatter_ptr = std::shared_ptr<spdlog::formatter>;
|
|
|
|
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
|
|
|
|
using level_t = details::null_atomic_int;
|
|
|
|
#else
|
2016-10-09 01:55:47 +03:00
|
|
|
using level_t = std::atomic<int>;
|
2016-08-22 20:54:18 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
using log_err_handler = std::function<void(const std::string &err_msg)>;
|
|
|
|
|
|
|
|
//Log level enum
|
|
|
|
namespace level
|
|
|
|
{
|
2018-02-24 22:35:09 +01:00
|
|
|
enum level_enum
|
2016-08-22 20:54:18 +03:00
|
|
|
{
|
|
|
|
trace = 0,
|
|
|
|
debug = 1,
|
|
|
|
info = 2,
|
|
|
|
warn = 3,
|
|
|
|
err = 4,
|
|
|
|
critical = 5,
|
|
|
|
off = 6
|
2018-02-24 22:35:09 +01:00
|
|
|
};
|
2016-08-22 20:54:18 +03:00
|
|
|
|
2017-07-05 02:46:45 +02:00
|
|
|
#if !defined(SPDLOG_LEVEL_NAMES)
|
2018-02-25 02:43:26 +01:00
|
|
|
#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off" }
|
2017-07-05 02:46:45 +02:00
|
|
|
#endif
|
2017-11-25 15:41:55 +02:00
|
|
|
static const char* level_names[] SPDLOG_LEVEL_NAMES;
|
2016-08-22 20:54:18 +03:00
|
|
|
|
|
|
|
static const char* short_level_names[] { "T", "D", "I", "W", "E", "C", "O" };
|
|
|
|
|
|
|
|
inline const char* to_str(spdlog::level::level_enum l)
|
|
|
|
{
|
|
|
|
return level_names[l];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const char* to_short_str(spdlog::level::level_enum l)
|
|
|
|
{
|
|
|
|
return short_level_names[l];
|
|
|
|
}
|
2018-01-24 23:08:46 -02:00
|
|
|
inline spdlog::level::level_enum to_level_enum(const char* name)
|
|
|
|
{
|
|
|
|
for (size_t level = 0; level < size(level_names); level++)
|
|
|
|
{
|
|
|
|
if (!strcmp(level_names[level], name))
|
|
|
|
{
|
|
|
|
return (spdlog::level::level_enum) level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (spdlog::level::level_enum) 0;
|
|
|
|
}
|
2018-02-05 12:20:57 +02:00
|
|
|
using level_hasher = std::hash<int>;
|
2016-08-22 20:54:18 +03:00
|
|
|
} //level
|
|
|
|
|
|
|
|
//
|
|
|
|
// Async overflow policy - block by default.
|
|
|
|
//
|
|
|
|
enum class async_overflow_policy
|
|
|
|
{
|
|
|
|
block_retry, // Block / yield / sleep until message can be enqueued
|
|
|
|
discard_log_msg // Discard the message it enqueue fails
|
|
|
|
};
|
|
|
|
|
2017-05-30 18:05:25 -04:00
|
|
|
//
|
|
|
|
// Pattern time - specific time getting to use for pattern_formatter.
|
|
|
|
// local time by default
|
|
|
|
//
|
2017-05-31 12:52:12 -04:00
|
|
|
enum class pattern_time_type
|
2017-05-30 18:05:25 -04:00
|
|
|
{
|
2017-06-01 03:42:10 +03:00
|
|
|
local, // log localtime
|
|
|
|
utc // log utc
|
2017-05-30 18:05:25 -04:00
|
|
|
};
|
2016-08-22 20:54:18 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// Log exception
|
|
|
|
//
|
|
|
|
namespace details
|
|
|
|
{
|
|
|
|
namespace os
|
|
|
|
{
|
|
|
|
std::string errno_str(int err_num);
|
|
|
|
}
|
|
|
|
}
|
2018-02-24 23:56:56 +01:00
|
|
|
class spdlog_ex : public std::exception
|
2016-08-22 20:54:18 +03:00
|
|
|
{
|
|
|
|
public:
|
2018-02-25 01:40:46 +01:00
|
|
|
explicit spdlog_ex(std::string msg) : _msg(std::move(msg))
|
2016-08-22 20:54:18 +03:00
|
|
|
{}
|
2018-02-25 01:40:46 +01:00
|
|
|
|
2016-08-22 20:54:18 +03:00
|
|
|
spdlog_ex(const std::string& msg, int last_errno)
|
|
|
|
{
|
|
|
|
_msg = msg + ": " + details::os::errno_str(last_errno);
|
|
|
|
}
|
2018-02-25 01:40:46 +01:00
|
|
|
|
2016-08-22 20:54:18 +03:00
|
|
|
const char* what() const SPDLOG_NOEXCEPT override
|
|
|
|
{
|
|
|
|
return _msg.c_str();
|
|
|
|
}
|
2018-02-24 23:56:56 +01:00
|
|
|
|
2016-08-22 20:54:18 +03:00
|
|
|
private:
|
|
|
|
std::string _msg;
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
|
|
|
|
//
|
|
|
|
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
|
|
|
using filename_t = std::wstring;
|
|
|
|
#else
|
|
|
|
using filename_t = std::string;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} //spdlog
|