added default_factory alias

This commit is contained in:
gabime 2018-04-20 01:55:31 +03:00
parent ba7c4c0530
commit 0969118ce7
2 changed files with 13 additions and 12 deletions

View File

@ -14,8 +14,8 @@
#include "spdlog/color_logger.h" #include "spdlog/color_logger.h"
#include "spdlog/stdout_logger.h" //#include "spdlog/stdout_logger.h"
#include "spdlog/async.h" //#include "spdlog/async.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include <iostream> #include <iostream>
@ -36,10 +36,10 @@ int main(int, char *[])
{ {
// Console logger with color // Console logger with color
spd::init_thread_pool(8192, 3); //spd::init_thread_pool(8192, 3);
auto console1 = spdlog::stdout_color_mt("console111"); auto console1 = spdlog::stdout_color_mt("console111");
auto console2 = spdlog::stdout_logger_mt<spdlog::create_async>("console2"); auto console2 = spdlog::stdout_color_mt<>("console2");
//auto console3 = spdlog::stdout_color_mt<spdlog::create_async>("console3"); //auto console3 = spdlog::stdout_color_mt<spdlog::create_async>("console3");
for (int i = 0; i < 10000; i++) for (int i = 0; i < 10000; i++)
{ {

View File

@ -40,6 +40,7 @@ struct create_synchronous
} }
}; };
using default_factory = create_synchronous;
@ -162,13 +163,13 @@ inline void drop_all()
// Create and register multi/single threaded basic file logger. // Create and register multi/single threaded basic file logger.
// Basic logger simply writes to given file without any limitations or rotations. // Basic logger simply writes to given file without any limitations or rotations.
// //
template<typename Factory = create_synchronous> template<typename Factory = default_factory>
inline std::shared_ptr<logger> basic_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false) 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); return Factory::template create<sinks::simple_file_sink_mt>(logger_name, filename, truncate);
} }
template<typename Factory = create_synchronous> template<typename Factory = default_factory>
inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false) 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); return Factory::template create<sinks::simple_file_sink_st>(logger_name, filename, truncate);
@ -177,14 +178,14 @@ inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, c
// //
// Create and register multi/single threaded rotating file logger // Create and register multi/single threaded rotating file logger
// //
template<typename Factory = create_synchronous> template<typename Factory = default_factory>
inline std::shared_ptr<logger> rotating_logger_mt( 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) 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); return Factory::template create<sinks::rotating_file_sink_mt>(logger_name, filename, max_file_size, max_files);
} }
template<typename Factory = create_synchronous> template<typename Factory = default_factory>
inline std::shared_ptr<logger> rotating_logger_st( 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) const std::string &logger_name, const filename_t &filename, size_t max_file_size, size_t max_files)
{ {
@ -194,13 +195,13 @@ inline std::shared_ptr<logger> rotating_logger_st(
// //
// Create file logger which creates new file on the given time (default in midnight): // Create file logger which creates new file on the given time (default in midnight):
// //
template<typename Factory = create_synchronous> template<typename Factory = default_factory>
inline std::shared_ptr<logger> daily_logger_mt(const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0) 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); return Factory::template create<sinks::daily_file_sink_mt>(logger_name, filename, hour, minute);
} }
template<typename Factory = create_synchronous> template<typename Factory = default_factory>
inline std::shared_ptr<logger> daily_logger_st(const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0) 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); return Factory::template create<sinks::daily_file_sink_st>(logger_name, filename, hour, minute);
@ -209,7 +210,7 @@ inline std::shared_ptr<logger> daily_logger_st(const std::string &logger_name, c
#ifdef SPDLOG_ENABLE_SYSLOG #ifdef SPDLOG_ENABLE_SYSLOG
// Create and register a syslog logger // Create and register a syslog logger
template<typename Factory = create_synchronous> template<typename Factory = default_factory>
inline std::shared_ptr<logger> syslog_logger( 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)) const std::string &logger_name, const std::string &ident = "", int syslog_option = 0, int syslog_facilty = (1 << 3))
{ {
@ -219,7 +220,7 @@ inline std::shared_ptr<logger> syslog_logger(
#if defined(__ANDROID__) #if defined(__ANDROID__)
// Create and register android syslog logger // Create and register android syslog logger
template<typename Factory = create_synchronous> template<typename Factory = default_factory>
inline std::shared_ptr<logger> android_logger(const std::string &logger_name, const std::string &tag = "spdlog") 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); return return Factory::template create<sinks::android_sink>(logger_name, tag);