mirror of https://github.com/gabime/spdlog.git
disable syslog by default (enable by #define SPDLOG_ENABLE_SYSLOG )
parent
c68a0de2b6
commit
20cb73e9da
@ -1,153 +1,143 @@
|
|||||||
//
|
//
|
||||||
// Copyright(c) 2015 Gabi Melman.
|
// Copyright(c) 2015 Gabi Melman.
|
||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include<functional>
|
#include<functional>
|
||||||
|
|
||||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <spdlog/details/null_mutex.h>
|
#include <spdlog/details/null_mutex.h>
|
||||||
|
|
||||||
//visual studio upto 2013 does not support noexcept nor constexpr
|
//visual studio upto 2013 does not support noexcept nor constexpr
|
||||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||||
#define SPDLOG_NOEXCEPT throw()
|
#define SPDLOG_NOEXCEPT throw()
|
||||||
#define SPDLOG_CONSTEXPR
|
#define SPDLOG_CONSTEXPR
|
||||||
#else
|
#else
|
||||||
#define SPDLOG_NOEXCEPT noexcept
|
#define SPDLOG_NOEXCEPT noexcept
|
||||||
#define SPDLOG_CONSTEXPR constexpr
|
#define SPDLOG_CONSTEXPR constexpr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
#define DEPRECATED __attribute__((deprecated))
|
#define DEPRECATED __attribute__((deprecated))
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
#define DEPRECATED __declspec(deprecated)
|
#define DEPRECATED __declspec(deprecated)
|
||||||
#else
|
#else
|
||||||
#define DEPRECATED
|
#define DEPRECATED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <spdlog/tweakme.h>
|
|
||||||
|
#include <spdlog/fmt/fmt.h>
|
||||||
#ifndef SPDLOG_ENABLE_SYSLOG
|
|
||||||
#if defined (__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
|
namespace spdlog
|
||||||
#define SPDLOG_ENABLE_SYSLOG
|
{
|
||||||
#elif defined(sun) || defined(__sun)
|
|
||||||
#define SPDLOG_ENABLE_SYSLOG
|
class formatter;
|
||||||
#endif
|
|
||||||
#endif
|
namespace sinks
|
||||||
|
{
|
||||||
|
class sink;
|
||||||
#include <spdlog/fmt/fmt.h>
|
}
|
||||||
|
|
||||||
namespace spdlog
|
using log_clock = std::chrono::system_clock;
|
||||||
{
|
using sink_ptr = std::shared_ptr < sinks::sink >;
|
||||||
|
using sinks_init_list = std::initializer_list < sink_ptr >;
|
||||||
class formatter;
|
using formatter_ptr = std::shared_ptr<spdlog::formatter>;
|
||||||
|
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
|
||||||
namespace sinks
|
using level_t = details::null_atomic_int;
|
||||||
{
|
#else
|
||||||
class sink;
|
using level_t = std::atomic_int;
|
||||||
}
|
#endif
|
||||||
|
|
||||||
using log_clock = std::chrono::system_clock;
|
using log_err_handler = std::function<void(const std::string &err_msg)>;
|
||||||
using sink_ptr = std::shared_ptr < sinks::sink >;
|
|
||||||
using sinks_init_list = std::initializer_list < sink_ptr >;
|
//Log level enum
|
||||||
using formatter_ptr = std::shared_ptr<spdlog::formatter>;
|
namespace level
|
||||||
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
|
{
|
||||||
using level_t = details::null_atomic_int;
|
typedef enum
|
||||||
#else
|
{
|
||||||
using level_t = std::atomic_int;
|
trace = 0,
|
||||||
#endif
|
debug = 1,
|
||||||
|
info = 2,
|
||||||
using log_err_handler = std::function<void(const std::string &err_msg)>;
|
warn = 3,
|
||||||
|
err = 4,
|
||||||
//Log level enum
|
critical = 5,
|
||||||
namespace level
|
off = 6
|
||||||
{
|
} level_enum;
|
||||||
typedef enum
|
|
||||||
{
|
static const char* level_names[]{ "trace", "debug", "info", "warning", "error", "critical", "off" };
|
||||||
trace = 0,
|
|
||||||
debug = 1,
|
static const char* short_level_names[]{ "T", "D", "I", "W", "E", "C", "O" };
|
||||||
info = 2,
|
|
||||||
warn = 3,
|
inline const char* to_str(spdlog::level::level_enum l)
|
||||||
err = 4,
|
{
|
||||||
critical = 5,
|
return level_names[l];
|
||||||
off = 6
|
}
|
||||||
} level_enum;
|
|
||||||
|
inline const char* to_short_str(spdlog::level::level_enum l)
|
||||||
static const char* level_names[] { "trace", "debug", "info", "warning", "error", "critical", "off" };
|
{
|
||||||
|
return short_level_names[l];
|
||||||
static const char* short_level_names[] { "T", "D", "I", "W", "E", "C", "O" };
|
}
|
||||||
|
} //level
|
||||||
inline const char* to_str(spdlog::level::level_enum l)
|
|
||||||
{
|
|
||||||
return level_names[l];
|
//
|
||||||
}
|
// Async overflow policy - block by default.
|
||||||
|
//
|
||||||
inline const char* to_short_str(spdlog::level::level_enum l)
|
enum class async_overflow_policy
|
||||||
{
|
{
|
||||||
return short_level_names[l];
|
block_retry, // Block / yield / sleep until message can be enqueued
|
||||||
}
|
discard_log_msg // Discard the message it enqueue fails
|
||||||
} //level
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Async overflow policy - block by default.
|
// Log exception
|
||||||
//
|
//
|
||||||
enum class async_overflow_policy
|
namespace details
|
||||||
{
|
{
|
||||||
block_retry, // Block / yield / sleep until message can be enqueued
|
namespace os
|
||||||
discard_log_msg // Discard the message it enqueue fails
|
{
|
||||||
};
|
std::string errno_str(int err_num);
|
||||||
|
}
|
||||||
|
}
|
||||||
//
|
class spdlog_ex: public std::exception
|
||||||
// Log exception
|
{
|
||||||
//
|
public:
|
||||||
namespace details
|
spdlog_ex(const std::string& msg):_msg(msg)
|
||||||
{
|
{}
|
||||||
namespace os
|
spdlog_ex(const std::string& msg, int last_errno)
|
||||||
{
|
{
|
||||||
std::string errno_str(int err_num);
|
_msg = msg + ": " + details::os::errno_str(last_errno);
|
||||||
}
|
}
|
||||||
}
|
const char* what() const SPDLOG_NOEXCEPT override
|
||||||
class spdlog_ex: public std::exception
|
{
|
||||||
{
|
return _msg.c_str();
|
||||||
public:
|
}
|
||||||
spdlog_ex(const std::string& msg):_msg(msg)
|
private:
|
||||||
{}
|
std::string _msg;
|
||||||
spdlog_ex(const std::string& msg, int last_errno)
|
|
||||||
{
|
};
|
||||||
_msg = msg + ": " + details::os::errno_str(last_errno);
|
|
||||||
}
|
//
|
||||||
const char* what() const SPDLOG_NOEXCEPT override
|
// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
|
||||||
{
|
//
|
||||||
return _msg.c_str();
|
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||||
}
|
using filename_t = std::wstring;
|
||||||
private:
|
#else
|
||||||
std::string _msg;
|
using filename_t = std::string;
|
||||||
|
#endif
|
||||||
};
|
|
||||||
|
|
||||||
//
|
} //spdlog
|
||||||
// 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
|
|
||||||
|
Loading…
Reference in New Issue