mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-12 00:40:26 +08:00
Added factory function overloads for QTextEdit, QPlainTextEdit and QObject
Added factory funtion overloads for QTextEdit, QPlainTextEdit and QObject objects cleaned qt_sink ctor
This commit is contained in:
parent
dabec32748
commit
fe9cb54e0d
@ -13,7 +13,6 @@
|
||||
#include "spdlog/details/synchronous_factory.h"
|
||||
#include "spdlog/sinks/base_sink.h"
|
||||
|
||||
#include <type_traits>
|
||||
#include <QTextEdit>
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
@ -25,12 +24,8 @@ namespace sinks {
|
||||
template <typename Mutex> class qt_sink : public base_sink<Mutex> {
|
||||
public:
|
||||
qt_sink(QObject *qt_object = nullptr, const std::string &meta_method = "") {
|
||||
if (qt_object != nullptr) {
|
||||
qt_object_ = qt_object;
|
||||
meta_method_ = meta_method;
|
||||
} else {
|
||||
throw spdlog_ex("Error opening qt sink");
|
||||
}
|
||||
}
|
||||
|
||||
~qt_sink() { flush_(); }
|
||||
@ -60,25 +55,39 @@ using qt_sink_st = qt_sink<spdlog::details::null_mutex>;
|
||||
//
|
||||
// Factory functions
|
||||
//
|
||||
template <typename T, typename Factory = spdlog::synchronous_factory>
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_mt(const std::string &logger_name, T *qt_object = nullptr, const std::string &meta_method = "") {
|
||||
std::string meta_method_ = meta_method;
|
||||
if (std::is_base_of<QTextEdit, T>::value)
|
||||
meta_method_ = "append";
|
||||
else if (std::is_same<T, QPlainTextEdit>::value)
|
||||
meta_method_ = "appendPlainText";
|
||||
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method_);
|
||||
qt_logger_mt(const std::string &logger_name, QTextEdit* qt_object, const std::string &meta_method = "append") {
|
||||
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template <typename T, typename Factory = spdlog::synchronous_factory>
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_st(const std::string &logger_name, T *qt_object = nullptr, const std::string &meta_method = "") {
|
||||
std::string meta_method_ = meta_method;
|
||||
if (std::is_base_of<QTextEdit, T>::value)
|
||||
meta_method_ = "append";
|
||||
else if (std::is_same<T, QPlainTextEdit>::value)
|
||||
meta_method_ = "appendPlainText";
|
||||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method_);
|
||||
qt_logger_st(const std::string &logger_name, QTextEdit* qt_object, const std::string &meta_method = "append") {
|
||||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_mt(const std::string &logger_name, QPlainTextEdit* qt_object , const std::string &meta_method = "appendPlainText") {
|
||||
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_st(const std::string &logger_name, QPlainTextEdit* qt_object, const std::string &meta_method = "appendPlainText") {
|
||||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_mt(const std::string &logger_name, QObject* qt_object, const std::string &meta_method) {
|
||||
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_st(const std::string &logger_name, QObject* qt_object, const std::string &meta_method) {
|
||||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
Loading…
Reference in New Issue
Block a user