|
|
|
@ -14,11 +14,6 @@
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "logger.h"
|
|
|
|
|
|
|
|
|
|
#if defined _WIN32
|
|
|
|
|
#include "sinks/wincolor_sink.h"
|
|
|
|
|
#else
|
|
|
|
|
#include "sinks/ansicolor_sink.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
|
#include "sinks/android_sink.h"
|
|
|
|
@ -32,7 +27,7 @@
|
|
|
|
|
namespace spdlog {
|
|
|
|
|
|
|
|
|
|
// Default logger factory- creates synchronous loggers
|
|
|
|
|
struct default_factory
|
|
|
|
|
struct create_synchronous
|
|
|
|
|
{
|
|
|
|
|
template<typename Sink, typename... SinkArgs>
|
|
|
|
|
|
|
|
|
@ -45,6 +40,41 @@ struct default_factory
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// color console loggers
|
|
|
|
|
//
|
|
|
|
|
// you must include "spdlog/sinks/color_sinks.h" before creating color loggers
|
|
|
|
|
//
|
|
|
|
|
// #include "spdlog/color_console.h"
|
|
|
|
|
//
|
|
|
|
|
// using namespace spdlog::sinks
|
|
|
|
|
// auto logger = spdlog::console<stdout_color_mt>("logger_name1");
|
|
|
|
|
// auto logger = spdlog::console<stdout_color_st>("logger_name2");
|
|
|
|
|
// auto looger = spdlog::console<stderr_color_mt>("logger_name3");
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// create asynchrounous color logger
|
|
|
|
|
// you must include "spdlog/asynch.h" before creating async loggers
|
|
|
|
|
//
|
|
|
|
|
// #include "spdlog/asynch."
|
|
|
|
|
// #include "spdlog/sinks/color_sinks.h"
|
|
|
|
|
// auto async_console = spdlog::console<stderr_color_st, spdlog::create_async>("some_name");
|
|
|
|
|
// or
|
|
|
|
|
// auto async_console = spdlog::create_async_logger<stdout_color_mt>("Console2");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//template<typename console_type, typename Factory = create_synchronous>
|
|
|
|
|
//inline std::shared_ptr<logger> console(const std::string &logger_name)
|
|
|
|
|
//{
|
|
|
|
|
// return Factory::template create<console_type>(logger_name);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create and register a logger with a templated sink type
|
|
|
|
|
// The logger's level, formatter and flush level will be set according the global settings.
|
|
|
|
|
// Example:
|
|
|
|
@ -52,7 +82,7 @@ struct default_factory
|
|
|
|
|
template<typename Sink, typename... SinkArgs>
|
|
|
|
|
inline std::shared_ptr<spdlog::logger> create(const std::string &logger_name, SinkArgs &&... sink_args)
|
|
|
|
|
{
|
|
|
|
|
return default_factory::create<Sink>(logger_name, std::forward<SinkArgs>(sink_args)...);
|
|
|
|
|
return create_synchronous::create<Sink>(logger_name, std::forward<SinkArgs>(sink_args)...);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
@ -132,13 +162,13 @@ inline void drop_all()
|
|
|
|
|
// Create and register multi/single threaded basic file logger.
|
|
|
|
|
// Basic logger simply writes to given file without any limitations or rotations.
|
|
|
|
|
//
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
template<typename Factory = create_synchronous>
|
|
|
|
|
inline std::shared_ptr<logger> basic_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::simple_file_sink_mt>(logger_name, filename, truncate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
template<typename Factory = create_synchronous>
|
|
|
|
|
inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::simple_file_sink_st>(logger_name, filename, truncate);
|
|
|
|
@ -147,14 +177,14 @@ inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, c
|
|
|
|
|
//
|
|
|
|
|
// Create and register multi/single threaded rotating file logger
|
|
|
|
|
//
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
template<typename Factory = create_synchronous>
|
|
|
|
|
inline std::shared_ptr<logger> rotating_logger_mt(
|
|
|
|
|
const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::rotating_file_sink_mt>(logger_name, filename, max_file_size, max_files);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
template<typename Factory = create_synchronous>
|
|
|
|
|
inline std::shared_ptr<logger> rotating_logger_st(
|
|
|
|
|
const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files)
|
|
|
|
|
{
|
|
|
|
@ -164,73 +194,22 @@ inline std::shared_ptr<logger> rotating_logger_st(
|
|
|
|
|
//
|
|
|
|
|
// Create file logger which creates new file on the given time (default in midnight):
|
|
|
|
|
//
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
template<typename Factory = create_synchronous>
|
|
|
|
|
inline std::shared_ptr<logger> daily_logger_mt(const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::daily_file_sink_mt>(logger_name, filename, hour, minute);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
template<typename Factory = create_synchronous>
|
|
|
|
|
inline std::shared_ptr<logger> daily_logger_st(const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::daily_file_sink_st>(logger_name, filename, hour, minute);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// color console logger
|
|
|
|
|
//
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
inline std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::stdout_color_mt>(logger_name);
|
|
|
|
|
}
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
inline std::shared_ptr<logger> stdout_color_st(const std::string &logger_name)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::stdout_color_st>(logger_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
inline std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::stderr_color_mt>(logger_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
inline std::shared_ptr<logger> stderr_color_st(const std::string &logger_name)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::stderr_color_st>(logger_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// console loggers (no colors)
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
inline std::shared_ptr<logger> stdout_logger_mt(const std::string &logger_name)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::stdout_sink_mt>(logger_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
inline std::shared_ptr<logger> stdout_logger_st(const std::string &logger_name)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::stdout_sink_st>(logger_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
inline std::shared_ptr<logger> stderr_logger_mt(const std::string &logger_name)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::stderr_sink_mt>(logger_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
inline std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name)
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::stderr_sink_st>(logger_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SPDLOG_ENABLE_SYSLOG
|
|
|
|
|
// Create and register a syslog logger
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
template<typename Factory = create_synchronous>
|
|
|
|
|
inline std::shared_ptr<logger> syslog_logger(
|
|
|
|
|
const std::string &logger_name, const std::string &ident = "", int syslog_option = 0, int syslog_facilty = (1 << 3))
|
|
|
|
|
{
|
|
|
|
@ -240,7 +219,7 @@ inline std::shared_ptr<logger> syslog_logger(
|
|
|
|
|
|
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
|
// Create and register android syslog logger
|
|
|
|
|
template<typename Factory = default_factory>
|
|
|
|
|
template<typename Factory = create_synchronous>
|
|
|
|
|
inline std::shared_ptr<logger> android_logger(const std::string &logger_name, const std::string &tag = "spdlog")
|
|
|
|
|
{
|
|
|
|
|
return return Factory::template create<sinks::android_sink>(logger_name, tag);
|
|
|
|
|