Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gabime/spdlog.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgabime <gmelman1@gmail.com>2019-06-03 23:56:18 +0300
committergabime <gmelman1@gmail.com>2019-06-03 23:56:18 +0300
commiteea9d6136f78ed69139a68439983cd00d16b58dd (patch)
treea34a8ff678e4328590c9b148b55b79604aa2c726 /include
parentc35f33e61afc487e99dd76d7b349b134b873ad18 (diff)
Moved default sync factory to seperate file to avoid cyclic includes
Diffstat (limited to 'include')
-rw-r--r--include/spdlog/common.h2
-rw-r--r--include/spdlog/details/registry.h4
-rw-r--r--include/spdlog/details/synchronous_factory.h22
-rw-r--r--include/spdlog/sinks/android_sink.h5
-rw-r--r--include/spdlog/sinks/ansicolor_sink.h1
-rw-r--r--include/spdlog/sinks/basic_file_sink.h5
-rw-r--r--include/spdlog/sinks/daily_file_sink.h5
-rw-r--r--include/spdlog/sinks/null_sink.h5
-rw-r--r--include/spdlog/sinks/rotating_file_sink.h5
-rw-r--r--include/spdlog/sinks/stdout_color_sinks.h11
-rw-r--r--include/spdlog/sinks/stdout_sinks.h9
-rw-r--r--include/spdlog/sinks/systemd_sink.h5
-rw-r--r--include/spdlog/spdlog.h14
13 files changed, 58 insertions, 35 deletions
diff --git a/include/spdlog/common.h b/include/spdlog/common.h
index 905f469b..47f79bdc 100644
--- a/include/spdlog/common.h
+++ b/include/spdlog/common.h
@@ -222,6 +222,8 @@ std::unique_ptr<T> make_unique(Args &&... args)
}
#endif
} // namespace details
+
+
} // namespace spdlog
#ifdef SPDLOG_HEADER_ONLY
diff --git a/include/spdlog/details/registry.h b/include/spdlog/details/registry.h
index bc6b2cc2..4070fa82 100644
--- a/include/spdlog/details/registry.h
+++ b/include/spdlog/details/registry.h
@@ -3,8 +3,8 @@
#pragma once
-// Loggers registy of unique name->logger pointer
-// An attempt to create a logger with an already existing name will be ignored
+// Loggers registry of unique name->logger pointer
+// An attempt to create a logger with an already existing name will result with spdlog_ex exception.
// If user requests a non existing logger, nullptr will be returned
// This class is thread safe
diff --git a/include/spdlog/details/synchronous_factory.h b/include/spdlog/details/synchronous_factory.h
new file mode 100644
index 00000000..2e9c1e41
--- /dev/null
+++ b/include/spdlog/details/synchronous_factory.h
@@ -0,0 +1,22 @@
+// Copyright(c) 2015-present Gabi Melman & spdlog contributors.
+// Distributed under the MIT License (http://opensource.org/licenses/MIT)
+
+#pragma once
+
+#include "registry.h"
+
+namespace spdlog {
+
+// Default logger factory- creates synchronous loggers
+ class logger;
+
+ struct synchronous_factory {
+ template<typename Sink, typename... SinkArgs>
+ static std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... args) {
+ auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
+ auto new_logger = std::make_shared<spdlog::logger>(std::move(logger_name), std::move(sink));
+ details::registry::instance().initialize_logger(new_logger);
+ return new_logger;
+ }
+ };
+} \ No newline at end of file
diff --git a/include/spdlog/sinks/android_sink.h b/include/spdlog/sinks/android_sink.h
index 36d78bf6..f2b7a683 100644
--- a/include/spdlog/sinks/android_sink.h
+++ b/include/spdlog/sinks/android_sink.h
@@ -7,6 +7,7 @@
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/os.h"
#include "spdlog/sinks/base_sink.h"
+#include "spdlog/details/synchronous_factory.h"
#include <android/log.h>
#include <chrono>
@@ -99,13 +100,13 @@ using android_sink_st = android_sink<details::null_mutex>;
// Create and register android syslog logger
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> android_logger_mt(const std::string &logger_name, const std::string &tag = "spdlog")
{
return Factory::template create<sinks::android_sink_mt>(logger_name, tag);
}
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> android_logger_st(const std::string &logger_name, const std::string &tag = "spdlog")
{
return Factory::template create<sinks::android_sink_st>(logger_name, tag);
diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h
index 8d9f7cd2..11ffd7fa 100644
--- a/include/spdlog/sinks/ansicolor_sink.h
+++ b/include/spdlog/sinks/ansicolor_sink.h
@@ -77,6 +77,7 @@ private:
void print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end);
};
+
using ansicolor_stdout_sink_mt = ansicolor_sink<details::console_stdout, details::console_mutex>;
using ansicolor_stdout_sink_st = ansicolor_sink<details::console_stdout, details::console_nullmutex>;
diff --git a/include/spdlog/sinks/basic_file_sink.h b/include/spdlog/sinks/basic_file_sink.h
index 5a8e38f6..366dba8e 100644
--- a/include/spdlog/sinks/basic_file_sink.h
+++ b/include/spdlog/sinks/basic_file_sink.h
@@ -6,6 +6,7 @@
#include "spdlog/details/file_helper.h"
#include "spdlog/details/null_mutex.h"
#include "spdlog/sinks/base_sink.h"
+#include "spdlog/details/synchronous_factory.h"
#include <mutex>
#include <string>
@@ -38,13 +39,13 @@ using basic_file_sink_st = basic_file_sink<details::null_mutex>;
//
// factory functions
//
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
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::basic_file_sink_mt>(logger_name, filename, truncate);
}
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
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::basic_file_sink_st>(logger_name, filename, truncate);
diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h
index 7c40f97b..e3f17864 100644
--- a/include/spdlog/sinks/daily_file_sink.h
+++ b/include/spdlog/sinks/daily_file_sink.h
@@ -8,6 +8,7 @@
#include "spdlog/fmt/fmt.h"
#include "spdlog/sinks/base_sink.h"
#include "spdlog/details/os.h"
+#include "spdlog/details/synchronous_factory.h"
#include <chrono>
#include <cstdio>
@@ -120,14 +121,14 @@ using daily_file_sink_st = daily_file_sink<details::null_mutex>;
//
// factory functions
//
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> daily_logger_mt(
const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false)
{
return Factory::template create<sinks::daily_file_sink_mt>(logger_name, filename, hour, minute, truncate);
}
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> daily_logger_st(
const std::string &logger_name, const filename_t &filename, int hour = 0, int minute = 0, bool truncate = false)
{
diff --git a/include/spdlog/sinks/null_sink.h b/include/spdlog/sinks/null_sink.h
index 800a992c..fd78a5ec 100644
--- a/include/spdlog/sinks/null_sink.h
+++ b/include/spdlog/sinks/null_sink.h
@@ -5,6 +5,7 @@
#include "spdlog/details/null_mutex.h"
#include "spdlog/sinks/base_sink.h"
+#include "spdlog/details/synchronous_factory.h"
#include <mutex>
@@ -24,7 +25,7 @@ using null_sink_st = null_sink<details::null_mutex>;
} // namespace sinks
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> null_logger_mt(const std::string &logger_name)
{
auto null_logger = Factory::template create<sinks::null_sink_mt>(logger_name);
@@ -32,7 +33,7 @@ inline std::shared_ptr<logger> null_logger_mt(const std::string &logger_name)
return null_logger;
}
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> null_logger_st(const std::string &logger_name)
{
auto null_logger = Factory::template create<sinks::null_sink_st>(logger_name);
diff --git a/include/spdlog/sinks/rotating_file_sink.h b/include/spdlog/sinks/rotating_file_sink.h
index a74d7095..6286eb6a 100644
--- a/include/spdlog/sinks/rotating_file_sink.h
+++ b/include/spdlog/sinks/rotating_file_sink.h
@@ -5,6 +5,7 @@
#include "spdlog/sinks/base_sink.h"
#include "spdlog/details/file_helper.h"
+#include "spdlog/details/synchronous_factory.h"
#include <chrono>
#include <mutex>
@@ -56,14 +57,14 @@ using rotating_file_sink_st = rotating_file_sink<details::null_mutex>;
// factory functions
//
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
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, bool rotate_on_open = false)
{
return Factory::template create<sinks::rotating_file_sink_mt>(logger_name, filename, max_file_size, max_files, rotate_on_open);
}
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
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, bool rotate_on_open = false)
{
diff --git a/include/spdlog/sinks/stdout_color_sinks.h b/include/spdlog/sinks/stdout_color_sinks.h
index ecdb42fd..6a9795f7 100644
--- a/include/spdlog/sinks/stdout_color_sinks.h
+++ b/include/spdlog/sinks/stdout_color_sinks.h
@@ -9,6 +9,8 @@
#include "spdlog/sinks/ansicolor_sink.h"
#endif
+#include "spdlog/details/synchronous_factory.h"
+
namespace spdlog {
namespace sinks {
#ifdef _WIN32
@@ -24,16 +26,17 @@ using stderr_color_sink_st = ansicolor_stderr_sink_st;
#endif
} // namespace sinks
-template<typename Factory = default_factory>
+
+template<typename Factory = spdlog::synchronous_factory>
std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic);
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
std::shared_ptr<logger> stdout_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic);
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic);
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
std::shared_ptr<logger> stderr_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic);
} // namespace spdlog
diff --git a/include/spdlog/sinks/stdout_sinks.h b/include/spdlog/sinks/stdout_sinks.h
index 85085130..117142c8 100644
--- a/include/spdlog/sinks/stdout_sinks.h
+++ b/include/spdlog/sinks/stdout_sinks.h
@@ -6,6 +6,7 @@
#include "spdlog/details/console_globals.h"
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/pattern_formatter.h"
+#include "spdlog/details/synchronous_factory.h"
#include <cstdio>
#include <memory>
@@ -70,25 +71,25 @@ using stderr_sink_st = stdout_sink<details::console_stderr, details::console_nul
} // namespace sinks
// factory methods
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_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>
+template<typename Factory = spdlog::synchronous_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>
+template<typename Factory = spdlog::synchronous_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>
+template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name)
{
return Factory::template create<sinks::stderr_sink_st>(logger_name);
diff --git a/include/spdlog/sinks/systemd_sink.h b/include/spdlog/sinks/systemd_sink.h
index 81af39de..da1c3e2c 100644
--- a/include/spdlog/sinks/systemd_sink.h
+++ b/include/spdlog/sinks/systemd_sink.h
@@ -4,6 +4,7 @@
#pragma once
#include "spdlog/sinks/base_sink.h"
+#include "spdlog/details/synchronous_factory.h"
#include <array>
#include <string>
@@ -65,13 +66,13 @@ using systemd_sink_st = systemd_sink<details::null_mutex>;
} // namespace sinks
// Create and register a syslog logger
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> systemd_logger_mt(const std::string &logger_name)
{
return Factory::template create<sinks::systemd_sink_mt>(logger_name);
}
-template<typename Factory = default_factory>
+template<typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> systemd_logger_st(const std::string &logger_name)
{
return Factory::template create<sinks::systemd_sink_st>(logger_name);
diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h
index 56a69e4c..ce32bc6e 100644
--- a/include/spdlog/spdlog.h
+++ b/include/spdlog/spdlog.h
@@ -13,6 +13,7 @@
#include "spdlog/details/registry.h"
#include "spdlog/logger.h"
#include "spdlog/version.h"
+#include "spdlog/details/synchronous_factory.h"
#include <chrono>
#include <functional>
@@ -21,19 +22,6 @@
namespace spdlog {
-// Default logger factory- creates synchronous loggers
-struct synchronous_factory
-{
- template<typename Sink, typename... SinkArgs>
- static std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... args)
- {
- auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
- auto new_logger = std::make_shared<logger>(std::move(logger_name), std::move(sink));
- details::registry::instance().initialize_logger(new_logger);
- return new_logger;
- }
-};
-
using default_factory = synchronous_factory;
// Create and register a logger with a templated sink type