2019-06-03 17:09:16 -04:00
|
|
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
2016-08-22 13:54:18 -04:00
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-04-28 18:31:09 -04:00
|
|
|
#include "spdlog/tweakme.h"
|
2018-02-23 07:34:25 -05:00
|
|
|
|
2016-08-22 13:54:18 -04:00
|
|
|
#include <atomic>
|
2018-03-09 08:24:37 -05:00
|
|
|
#include <chrono>
|
|
|
|
#include <initializer_list>
|
|
|
|
#include <memory>
|
2019-07-16 08:50:42 -04:00
|
|
|
#include <exception>
|
2018-03-09 08:24:37 -05:00
|
|
|
#include <string>
|
2019-04-05 18:44:03 -04:00
|
|
|
#include <type_traits>
|
2019-04-26 19:33:33 -04:00
|
|
|
#include <functional>
|
2016-08-22 13:54:18 -04:00
|
|
|
|
2019-06-18 05:32:51 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
#ifndef NOMINMAX
|
|
|
|
#define NOMINMAX // prevent windows redefining min/max
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#endif //_WIN32
|
|
|
|
|
2019-05-18 00:09:22 -04:00
|
|
|
#ifdef SPDLOG_COMPILED_LIB
|
2019-05-11 17:22:39 -04:00
|
|
|
#undef SPDLOG_HEADER_ONLY
|
2019-04-05 09:44:17 -04:00
|
|
|
#define SPDLOG_INLINE
|
2019-04-27 11:44:48 -04:00
|
|
|
#else
|
2019-05-11 17:22:39 -04:00
|
|
|
#define SPDLOG_HEADER_ONLY
|
2019-04-27 11:44:48 -04:00
|
|
|
#define SPDLOG_INLINE inline
|
2019-04-05 09:44:17 -04:00
|
|
|
#endif
|
|
|
|
|
2019-05-11 17:32:57 -04:00
|
|
|
#include "spdlog/fmt/fmt.h"
|
|
|
|
|
2018-03-09 08:24:37 -05:00
|
|
|
// visual studio upto 2013 does not support noexcept nor constexpr
|
2016-08-22 13:54:18 -04:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
|
|
|
#define SPDLOG_NOEXCEPT throw()
|
|
|
|
#define SPDLOG_CONSTEXPR
|
|
|
|
#else
|
|
|
|
#define SPDLOG_NOEXCEPT noexcept
|
|
|
|
#define SPDLOG_CONSTEXPR constexpr
|
|
|
|
#endif
|
|
|
|
|
2018-03-09 08:24:37 -05:00
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
2016-11-14 07:58:10 -05:00
|
|
|
#define SPDLOG_DEPRECATED __attribute__((deprecated))
|
2016-08-22 13:54:18 -04:00
|
|
|
#elif defined(_MSC_VER)
|
2016-11-14 07:58:10 -05:00
|
|
|
#define SPDLOG_DEPRECATED __declspec(deprecated)
|
2016-08-22 13:54:18 -04:00
|
|
|
#else
|
2016-11-14 07:58:10 -05:00
|
|
|
#define SPDLOG_DEPRECATED
|
2016-08-22 13:54:18 -04:00
|
|
|
#endif
|
|
|
|
|
2018-11-16 03:07:31 -05:00
|
|
|
// disable thread local on msvc 2013
|
|
|
|
#ifndef SPDLOG_NO_TLS
|
2019-01-08 10:35:34 -05:00
|
|
|
#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__cplusplus_winrt)
|
2018-11-16 03:07:31 -05:00
|
|
|
#define SPDLOG_NO_TLS 1
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2019-01-10 12:18:31 -05:00
|
|
|
#ifndef SPDLOG_FUNCTION
|
|
|
|
#define SPDLOG_FUNCTION __FUNCTION__
|
|
|
|
#endif
|
|
|
|
|
2019-08-18 12:46:28 -04:00
|
|
|
#ifdef SPDLOG_NO_EXCEPTIONS
|
2019-08-19 04:31:33 -04:00
|
|
|
#define SPDLOG_TRY
|
|
|
|
#define SPDLOG_THROW(ex) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
printf("spdlog fatal error: %s\n", ex.what()); \
|
|
|
|
std::abort(); \
|
|
|
|
} while (0)
|
|
|
|
#define SPDLOG_CATCH_ALL()
|
2019-08-18 12:46:28 -04:00
|
|
|
#else
|
2019-08-19 04:31:33 -04:00
|
|
|
#define SPDLOG_TRY try
|
|
|
|
#define SPDLOG_THROW(ex) throw(ex)
|
|
|
|
#define SPDLOG_CATCH_ALL() catch (...)
|
2019-08-18 12:46:28 -04:00
|
|
|
#endif
|
|
|
|
|
2019-04-06 06:45:33 -04:00
|
|
|
namespace spdlog {
|
|
|
|
|
|
|
|
class formatter;
|
|
|
|
|
|
|
|
namespace sinks {
|
|
|
|
class sink;
|
|
|
|
}
|
|
|
|
|
2019-04-05 16:05:46 -04:00
|
|
|
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
2019-04-05 18:37:27 -04:00
|
|
|
using filename_t = std::wstring;
|
2019-04-05 16:05:46 -04:00
|
|
|
#define SPDLOG_FILENAME_T(s) L##s
|
|
|
|
#else
|
2019-04-05 18:37:27 -04:00
|
|
|
using filename_t = std::string;
|
2019-04-05 16:05:46 -04:00
|
|
|
#define SPDLOG_FILENAME_T(s) s
|
|
|
|
#endif
|
|
|
|
|
2016-08-22 13:54:18 -04:00
|
|
|
using log_clock = std::chrono::system_clock;
|
2018-03-09 08:24:37 -05:00
|
|
|
using sink_ptr = std::shared_ptr<sinks::sink>;
|
|
|
|
using sinks_init_list = std::initializer_list<sink_ptr>;
|
2019-04-26 19:33:33 -04:00
|
|
|
using err_handler = std::function<void(const std::string &err_msg)>;
|
2018-07-07 17:53:50 -04:00
|
|
|
|
2019-06-30 19:00:28 -04:00
|
|
|
template<typename T>
|
|
|
|
using basic_string_view_t = fmt::basic_string_view<T>;
|
2019-07-07 10:22:58 -04:00
|
|
|
|
2019-06-30 19:00:28 -04:00
|
|
|
using string_view_t = basic_string_view_t<char>;
|
2019-07-07 10:22:58 -04:00
|
|
|
|
2019-07-06 12:59:45 -04:00
|
|
|
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
|
|
|
#ifndef _WIN32
|
|
|
|
#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
|
|
|
|
#else
|
|
|
|
using wstring_view_t = basic_string_view_t<wchar_t>;
|
2019-07-24 13:46:59 -04:00
|
|
|
|
|
|
|
template<typename T>
|
2019-08-19 04:31:33 -04:00
|
|
|
struct is_convertible_to_wstring_view : std::is_convertible<T, wstring_view_t>
|
|
|
|
{};
|
2019-07-06 12:59:45 -04:00
|
|
|
#endif // _WIN32
|
2019-07-24 13:46:59 -04:00
|
|
|
#else
|
|
|
|
template<typename>
|
2019-08-19 04:31:33 -04:00
|
|
|
struct is_convertible_to_wstring_view : std::false_type
|
|
|
|
{};
|
2019-07-06 12:59:45 -04:00
|
|
|
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
2018-10-21 05:46:58 -04:00
|
|
|
|
2016-08-22 13:54:18 -04:00
|
|
|
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
|
|
|
|
using level_t = details::null_atomic_int;
|
|
|
|
#else
|
2016-10-08 18:55:47 -04:00
|
|
|
using level_t = std::atomic<int>;
|
2016-08-22 13:54:18 -04:00
|
|
|
#endif
|
|
|
|
|
2018-11-11 11:15:24 -05:00
|
|
|
#define SPDLOG_LEVEL_TRACE 0
|
|
|
|
#define SPDLOG_LEVEL_DEBUG 1
|
|
|
|
#define SPDLOG_LEVEL_INFO 2
|
|
|
|
#define SPDLOG_LEVEL_WARN 3
|
|
|
|
#define SPDLOG_LEVEL_ERROR 4
|
|
|
|
#define SPDLOG_LEVEL_CRITICAL 5
|
|
|
|
#define SPDLOG_LEVEL_OFF 6
|
|
|
|
|
|
|
|
#if !defined(SPDLOG_ACTIVE_LEVEL)
|
|
|
|
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
|
|
|
|
#endif
|
|
|
|
|
2018-03-09 08:24:37 -05:00
|
|
|
// Log level enum
|
|
|
|
namespace level {
|
2018-02-24 16:35:09 -05:00
|
|
|
enum level_enum
|
2016-08-22 13:54:18 -04:00
|
|
|
{
|
2018-11-11 11:15:24 -05:00
|
|
|
trace = SPDLOG_LEVEL_TRACE,
|
|
|
|
debug = SPDLOG_LEVEL_DEBUG,
|
|
|
|
info = SPDLOG_LEVEL_INFO,
|
|
|
|
warn = SPDLOG_LEVEL_WARN,
|
|
|
|
err = SPDLOG_LEVEL_ERROR,
|
|
|
|
critical = SPDLOG_LEVEL_CRITICAL,
|
|
|
|
off = SPDLOG_LEVEL_OFF,
|
2018-02-24 16:35:09 -05:00
|
|
|
};
|
2016-08-22 13:54:18 -04:00
|
|
|
|
2017-07-04 20:46:45 -04:00
|
|
|
#if !defined(SPDLOG_LEVEL_NAMES)
|
2018-03-09 08:24:37 -05:00
|
|
|
#define SPDLOG_LEVEL_NAMES \
|
|
|
|
{ \
|
|
|
|
"trace", "debug", "info", "warning", "error", "critical", "off" \
|
|
|
|
}
|
2017-07-04 20:46:45 -04:00
|
|
|
#endif
|
2019-02-18 16:33:41 -05:00
|
|
|
|
|
|
|
#if !defined(SPDLOG_SHORT_LEVEL_NAMES)
|
2019-05-11 17:22:39 -04:00
|
|
|
|
2019-03-23 10:39:32 -04:00
|
|
|
#define SPDLOG_SHORT_LEVEL_NAMES \
|
|
|
|
{ \
|
|
|
|
"T", "D", "I", "W", "E", "C", "O" \
|
|
|
|
}
|
2019-02-18 16:33:41 -05:00
|
|
|
#endif
|
2016-08-22 13:54:18 -04:00
|
|
|
|
2019-05-11 17:22:39 -04:00
|
|
|
string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT;
|
|
|
|
const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT;
|
|
|
|
spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT;
|
2018-03-08 17:08:24 -05:00
|
|
|
|
2018-02-05 05:20:57 -05:00
|
|
|
using level_hasher = std::hash<int>;
|
2018-03-09 08:24:37 -05:00
|
|
|
} // namespace level
|
2016-08-22 13:54:18 -04:00
|
|
|
|
2019-05-09 07:16:38 -04:00
|
|
|
//
|
|
|
|
// Color mode used by sinks with color support.
|
|
|
|
//
|
|
|
|
enum class color_mode
|
|
|
|
{
|
|
|
|
always,
|
|
|
|
automatic,
|
|
|
|
never
|
|
|
|
};
|
|
|
|
|
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-05-31 20:42:10 -04:00
|
|
|
local, // log localtime
|
|
|
|
utc // log utc
|
2017-05-30 18:05:25 -04:00
|
|
|
};
|
2016-08-22 13:54:18 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Log exception
|
|
|
|
//
|
2018-08-15 12:01:44 -04:00
|
|
|
class spdlog_ex : public std::exception
|
2016-08-22 13:54:18 -04:00
|
|
|
{
|
|
|
|
public:
|
2019-05-11 13:15:03 -04:00
|
|
|
explicit spdlog_ex(std::string msg);
|
|
|
|
spdlog_ex(const std::string &msg, int last_errno);
|
|
|
|
const char *what() const SPDLOG_NOEXCEPT override;
|
2018-06-13 13:16:31 -04:00
|
|
|
|
2016-08-22 13:54:18 -04:00
|
|
|
private:
|
2018-08-15 12:01:44 -04:00
|
|
|
std::string msg_;
|
2016-08-22 13:54:18 -04:00
|
|
|
};
|
|
|
|
|
2018-11-22 11:47:50 -05:00
|
|
|
struct source_loc
|
|
|
|
{
|
2019-04-05 18:44:03 -04:00
|
|
|
SPDLOG_CONSTEXPR source_loc() = default;
|
2019-02-01 07:59:50 -05:00
|
|
|
SPDLOG_CONSTEXPR source_loc(const char *filename_in, int line_in, const char *funcname_in)
|
|
|
|
: filename{filename_in}
|
2019-04-05 18:44:03 -04:00
|
|
|
, line{line_in}
|
2019-02-01 07:59:50 -05:00
|
|
|
, funcname{funcname_in}
|
2019-05-11 17:22:39 -04:00
|
|
|
{}
|
2018-11-24 17:44:51 -05:00
|
|
|
|
|
|
|
SPDLOG_CONSTEXPR bool empty() const SPDLOG_NOEXCEPT
|
|
|
|
{
|
|
|
|
return line == 0;
|
|
|
|
}
|
2019-04-05 18:44:03 -04:00
|
|
|
const char *filename{nullptr};
|
|
|
|
int line{0};
|
|
|
|
const char *funcname{nullptr};
|
2018-11-22 11:47:50 -05:00
|
|
|
};
|
|
|
|
|
2018-09-26 16:48:36 -04:00
|
|
|
namespace details {
|
|
|
|
// make_unique support for pre c++14
|
|
|
|
|
2018-09-01 14:30:05 -04:00
|
|
|
#if __cplusplus >= 201402L // C++14 and beyond
|
|
|
|
using std::make_unique;
|
|
|
|
#else
|
|
|
|
template<typename T, typename... Args>
|
|
|
|
std::unique_ptr<T> make_unique(Args &&... args)
|
|
|
|
{
|
2018-09-26 16:50:47 -04:00
|
|
|
static_assert(!std::is_array<T>::value, "arrays not supported");
|
2018-09-01 14:30:05 -04:00
|
|
|
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
|
|
|
}
|
|
|
|
#endif
|
2018-09-26 16:48:36 -04:00
|
|
|
} // namespace details
|
2019-06-03 16:56:18 -04:00
|
|
|
|
2018-03-09 08:24:37 -05:00
|
|
|
} // namespace spdlog
|
2019-05-11 13:15:03 -04:00
|
|
|
|
2019-05-11 17:22:39 -04:00
|
|
|
#ifdef SPDLOG_HEADER_ONLY
|
|
|
|
#include "common-inl.h"
|
2019-05-18 00:09:22 -04:00
|
|
|
#endif
|