|
|
@ -22,22 +22,24 @@ namespace _sinks_p {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Private class for QTextEdit and its derivatives
|
|
|
|
// Private class for QTextEdit and its derivatives
|
|
|
|
//
|
|
|
|
//
|
|
|
|
class qtextedit_sink_p : public QObject {
|
|
|
|
class qtextedit_sink_p : public QObject
|
|
|
|
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
qtextedit_sink_p(QTextEdit *textedit = nullptr) {
|
|
|
|
qtextedit_sink_p(QTextEdit *textedit = nullptr)
|
|
|
|
if (textedit != nullptr) {
|
|
|
|
{
|
|
|
|
|
|
|
|
if (textedit != nullptr)
|
|
|
|
|
|
|
|
{
|
|
|
|
textedit_ = textedit;
|
|
|
|
textedit_ = textedit;
|
|
|
|
connect(this, &qtextedit_sink_p::append_text, textedit_,
|
|
|
|
connect(this, &qtextedit_sink_p::append_text, textedit_, &QTextEdit::append);
|
|
|
|
&QTextEdit::append);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
~qtextedit_sink_p() {}
|
|
|
|
~qtextedit_sink_p() {}
|
|
|
|
|
|
|
|
|
|
|
|
void append(const spdlog::string_view_t &str) {
|
|
|
|
void append(const spdlog::string_view_t &str)
|
|
|
|
emit append_text(
|
|
|
|
{
|
|
|
|
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
|
|
|
emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
signals:
|
|
|
@ -50,22 +52,24 @@ private:
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Private class for QPlainTextEdit
|
|
|
|
// Private class for QPlainTextEdit
|
|
|
|
//
|
|
|
|
//
|
|
|
|
class qplaintextedit_sink_p : public QObject {
|
|
|
|
class qplaintextedit_sink_p : public QObject
|
|
|
|
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr) {
|
|
|
|
qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr)
|
|
|
|
if (textedit != nullptr) {
|
|
|
|
{
|
|
|
|
|
|
|
|
if (textedit != nullptr)
|
|
|
|
|
|
|
|
{
|
|
|
|
textedit_ = textedit;
|
|
|
|
textedit_ = textedit;
|
|
|
|
connect(this, &qplaintextedit_sink_p::append_text, textedit_,
|
|
|
|
connect(this, &qplaintextedit_sink_p::append_text, textedit_, &QPlainTextEdit::appendPlainText);
|
|
|
|
&QPlainTextEdit::appendPlainText);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
~qplaintextedit_sink_p() {}
|
|
|
|
~qplaintextedit_sink_p() {}
|
|
|
|
|
|
|
|
|
|
|
|
void append(const spdlog::string_view_t &str) {
|
|
|
|
void append(const spdlog::string_view_t &str)
|
|
|
|
emit append_text(
|
|
|
|
{
|
|
|
|
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
|
|
|
emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
signals:
|
|
|
@ -82,21 +86,30 @@ private:
|
|
|
|
//
|
|
|
|
//
|
|
|
|
namespace spdlog {
|
|
|
|
namespace spdlog {
|
|
|
|
namespace sinks {
|
|
|
|
namespace sinks {
|
|
|
|
template <typename Mutex> class qtextedit_sink : public base_sink<Mutex> {
|
|
|
|
template<typename Mutex>
|
|
|
|
|
|
|
|
class qtextedit_sink : public base_sink<Mutex>
|
|
|
|
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
qtextedit_sink(QTextEdit *textedit = nullptr) {
|
|
|
|
qtextedit_sink(QTextEdit *textedit = nullptr)
|
|
|
|
if (textedit != nullptr) {
|
|
|
|
{
|
|
|
|
textedit_p =
|
|
|
|
if (textedit != nullptr)
|
|
|
|
std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit);
|
|
|
|
{
|
|
|
|
} else {
|
|
|
|
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
throw spdlog_ex("Error opening QTextEdit");
|
|
|
|
throw spdlog_ex("Error opening QTextEdit");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
~qtextedit_sink() { flush_(); }
|
|
|
|
~qtextedit_sink()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
flush_();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
protected:
|
|
|
|
void sink_it_(const details::log_msg &msg) override {
|
|
|
|
void sink_it_(const details::log_msg &msg) override
|
|
|
|
|
|
|
|
{
|
|
|
|
memory_buf_t formatted;
|
|
|
|
memory_buf_t formatted;
|
|
|
|
base_sink<Mutex>::formatter_->format(msg, formatted);
|
|
|
|
base_sink<Mutex>::formatter_->format(msg, formatted);
|
|
|
|
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
|
|
|
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
|
|
@ -112,21 +125,30 @@ private:
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// qplaintextedit_sink class
|
|
|
|
// qplaintextedit_sink class
|
|
|
|
//
|
|
|
|
//
|
|
|
|
template <typename Mutex> class qplaintextedit_sink : public base_sink<Mutex> {
|
|
|
|
template<typename Mutex>
|
|
|
|
|
|
|
|
class qplaintextedit_sink : public base_sink<Mutex>
|
|
|
|
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
qplaintextedit_sink(QPlainTextEdit *textedit = nullptr) {
|
|
|
|
qplaintextedit_sink(QPlainTextEdit *textedit = nullptr)
|
|
|
|
if (textedit != nullptr) {
|
|
|
|
{
|
|
|
|
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>(
|
|
|
|
if (textedit != nullptr)
|
|
|
|
textedit);
|
|
|
|
{
|
|
|
|
} else {
|
|
|
|
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>(textedit);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
throw spdlog_ex("Error opening QPlainTextEdit");
|
|
|
|
throw spdlog_ex("Error opening QPlainTextEdit");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
~qplaintextedit_sink() { flush_(); }
|
|
|
|
~qplaintextedit_sink()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
flush_();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
protected:
|
|
|
|
void sink_it_(const details::log_msg &msg) override {
|
|
|
|
void sink_it_(const details::log_msg &msg) override
|
|
|
|
|
|
|
|
{
|
|
|
|
memory_buf_t formatted;
|
|
|
|
memory_buf_t formatted;
|
|
|
|
base_sink<Mutex>::formatter_->format(msg, formatted);
|
|
|
|
base_sink<Mutex>::formatter_->format(msg, formatted);
|
|
|
|
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
|
|
|
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
|
|
@ -136,8 +158,7 @@ protected:
|
|
|
|
void flush_() override {}
|
|
|
|
void flush_() override {}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p =
|
|
|
|
std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p = nullptr;
|
|
|
|
nullptr;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#include "spdlog/details/null_mutex.h"
|
|
|
|
#include "spdlog/details/null_mutex.h"
|
|
|
@ -154,34 +175,26 @@ using qplaintextedit_sink_st = qplaintextedit_sink<spdlog::details::null_mutex>;
|
|
|
|
// Factory functions
|
|
|
|
// Factory functions
|
|
|
|
//
|
|
|
|
//
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
inline std::shared_ptr<logger>
|
|
|
|
inline std::shared_ptr<logger> qtextedit_logger_mt(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
|
|
|
|
qtextedit_logger_mt(const std::string &logger_name,
|
|
|
|
{
|
|
|
|
QTextEdit *qtextedit = nullptr) {
|
|
|
|
return Factory::template create<sinks::qtextedit_sink_mt>(logger_name, qtextedit);
|
|
|
|
return Factory::template create<sinks::qtextedit_sink_mt>(logger_name,
|
|
|
|
|
|
|
|
qtextedit);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
inline std::shared_ptr<logger>
|
|
|
|
inline std::shared_ptr<logger> qtextedit_logger_st(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
|
|
|
|
qtextedit_logger_st(const std::string &logger_name,
|
|
|
|
{
|
|
|
|
QTextEdit *qtextedit = nullptr) {
|
|
|
|
return Factory::template create<sinks::qtextedit_sink_st>(logger_name, qtextedit);
|
|
|
|
return Factory::template create<sinks::qtextedit_sink_st>(logger_name,
|
|
|
|
|
|
|
|
qtextedit);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
inline std::shared_ptr<logger>
|
|
|
|
inline std::shared_ptr<logger> qplaintextedit_logger_mt(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
|
|
|
|
qplaintextedit_logger_mt(const std::string &logger_name,
|
|
|
|
{
|
|
|
|
QPlainTextEdit *qplaintextedit = nullptr) {
|
|
|
|
return Factory::template create<sinks::qplaintextedit_sink_mt>(logger_name, qplaintextedit);
|
|
|
|
return Factory::template create<sinks::qplaintextedit_sink_mt>(
|
|
|
|
|
|
|
|
logger_name, qplaintextedit);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
inline std::shared_ptr<logger>
|
|
|
|
inline std::shared_ptr<logger> qplaintextedit_logger_st(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
|
|
|
|
qplaintextedit_logger_st(const std::string &logger_name,
|
|
|
|
{
|
|
|
|
QPlainTextEdit *qplaintextedit = nullptr) {
|
|
|
|
return Factory::template create<sinks::qplaintextedit_sink_st>(logger_name, qplaintextedit);
|
|
|
|
return Factory::template create<sinks::qplaintextedit_sink_st>(
|
|
|
|
|
|
|
|
logger_name, qplaintextedit);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace spdlog
|
|
|
|
} // namespace spdlog
|
|
|
|