mirror of https://github.com/gabime/spdlog.git
clang-format
parent
e98265a49b
commit
e7e8b75a4c
@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef NOMINMAX
|
#ifndef NOMINMAX
|
||||||
#define NOMINMAX // prevent windows redefining min/max
|
# define NOMINMAX // prevent windows redefining min/max
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
#define WIN32_LEAN_AND_MEAN
|
# define WIN32_LEAN_AND_MEAN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
@ -1,187 +1,200 @@
|
|||||||
// Copyright(c) 2015-present, Gabi Melman, mguludag and spdlog contributors.
|
// Copyright(c) 2015-present, Gabi Melman, mguludag and spdlog contributors.
|
||||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//
|
//
|
||||||
// Custom sink for QPlainTextEdit or QTextEdit and its children(QTextBrowser...
|
// Custom sink for QPlainTextEdit or QTextEdit and its children(QTextBrowser...
|
||||||
// etc) Building and using requires Qt library.
|
// etc) Building and using requires Qt library.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "spdlog/common.h"
|
#include "spdlog/common.h"
|
||||||
#include "spdlog/details/log_msg.h"
|
#include "spdlog/details/log_msg.h"
|
||||||
#include "spdlog/details/synchronous_factory.h"
|
#include "spdlog/details/synchronous_factory.h"
|
||||||
#include "spdlog/sinks/base_sink.h"
|
#include "spdlog/sinks/base_sink.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
|
||||||
namespace _spdlog_p {
|
namespace _spdlog_p {
|
||||||
namespace _sinks_p {
|
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
|
{
|
||||||
public:
|
Q_OBJECT
|
||||||
qtextedit_sink_p(QTextEdit *textedit = nullptr) {
|
public:
|
||||||
if (textedit != nullptr) {
|
qtextedit_sink_p(QTextEdit *textedit = nullptr)
|
||||||
textedit_ = textedit;
|
{
|
||||||
connect(this, &qtextedit_sink_p::append_text, textedit_,
|
if (textedit != nullptr)
|
||||||
&QTextEdit::append);
|
{
|
||||||
}
|
textedit_ = textedit;
|
||||||
}
|
connect(this, &qtextedit_sink_p::append_text, textedit_, &QTextEdit::append);
|
||||||
|
}
|
||||||
~qtextedit_sink_p() {}
|
}
|
||||||
|
|
||||||
void append(const spdlog::string_view_t &str) {
|
~qtextedit_sink_p() {}
|
||||||
emit append_text(
|
|
||||||
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
void append(const spdlog::string_view_t &str)
|
||||||
}
|
{
|
||||||
|
emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
||||||
signals:
|
}
|
||||||
void append_text(const QString &);
|
|
||||||
|
signals:
|
||||||
private:
|
void append_text(const QString &);
|
||||||
QTextEdit *textedit_ = nullptr;
|
|
||||||
};
|
private:
|
||||||
|
QTextEdit *textedit_ = nullptr;
|
||||||
//
|
};
|
||||||
// Private class for QPlainTextEdit
|
|
||||||
//
|
//
|
||||||
class qplaintextedit_sink_p : public QObject {
|
// Private class for QPlainTextEdit
|
||||||
Q_OBJECT
|
//
|
||||||
public:
|
class qplaintextedit_sink_p : public QObject
|
||||||
qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr) {
|
{
|
||||||
if (textedit != nullptr) {
|
Q_OBJECT
|
||||||
textedit_ = textedit;
|
public:
|
||||||
connect(this, &qplaintextedit_sink_p::append_text, textedit_,
|
qplaintextedit_sink_p(QPlainTextEdit *textedit = nullptr)
|
||||||
&QPlainTextEdit::appendPlainText);
|
{
|
||||||
}
|
if (textedit != nullptr)
|
||||||
}
|
{
|
||||||
|
textedit_ = textedit;
|
||||||
~qplaintextedit_sink_p() {}
|
connect(this, &qplaintextedit_sink_p::append_text, textedit_, &QPlainTextEdit::appendPlainText);
|
||||||
|
}
|
||||||
void append(const spdlog::string_view_t &str) {
|
}
|
||||||
emit append_text(
|
|
||||||
QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
~qplaintextedit_sink_p() {}
|
||||||
}
|
|
||||||
|
void append(const spdlog::string_view_t &str)
|
||||||
signals:
|
{
|
||||||
void append_text(const QString &);
|
emit append_text(QString::fromUtf8(str.data(), static_cast<int>(str.size() - 2)));
|
||||||
|
}
|
||||||
private:
|
|
||||||
QPlainTextEdit *textedit_ = nullptr;
|
signals:
|
||||||
};
|
void append_text(const QString &);
|
||||||
} // namespace _sinks_p
|
|
||||||
} // namespace _spdlog_p
|
private:
|
||||||
|
QPlainTextEdit *textedit_ = nullptr;
|
||||||
//
|
};
|
||||||
// qtextedit_sink class
|
} // namespace _sinks_p
|
||||||
//
|
} // namespace _spdlog_p
|
||||||
namespace spdlog {
|
|
||||||
namespace sinks {
|
//
|
||||||
template <typename Mutex> class qtextedit_sink : public base_sink<Mutex> {
|
// qtextedit_sink class
|
||||||
public:
|
//
|
||||||
qtextedit_sink(QTextEdit *textedit = nullptr) {
|
namespace spdlog {
|
||||||
if (textedit != nullptr) {
|
namespace sinks {
|
||||||
textedit_p =
|
template<typename Mutex>
|
||||||
std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit);
|
class qtextedit_sink : public base_sink<Mutex>
|
||||||
} else {
|
{
|
||||||
throw spdlog_ex("Error opening QTextEdit");
|
public:
|
||||||
}
|
qtextedit_sink(QTextEdit *textedit = nullptr)
|
||||||
}
|
{
|
||||||
|
if (textedit != nullptr)
|
||||||
~qtextedit_sink() { flush_(); }
|
{
|
||||||
|
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qtextedit_sink_p>(textedit);
|
||||||
protected:
|
}
|
||||||
void sink_it_(const details::log_msg &msg) override {
|
else
|
||||||
memory_buf_t formatted;
|
{
|
||||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
throw spdlog_ex("Error opening QTextEdit");
|
||||||
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
}
|
||||||
textedit_p->append(str_v);
|
}
|
||||||
}
|
|
||||||
|
~qtextedit_sink()
|
||||||
void flush_() override {}
|
{
|
||||||
|
flush_();
|
||||||
private:
|
}
|
||||||
std::shared_ptr<_spdlog_p::_sinks_p::qtextedit_sink_p> textedit_p = nullptr;
|
|
||||||
};
|
protected:
|
||||||
|
void sink_it_(const details::log_msg &msg) override
|
||||||
//
|
{
|
||||||
// qplaintextedit_sink class
|
memory_buf_t formatted;
|
||||||
//
|
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||||
template <typename Mutex> class qplaintextedit_sink : public base_sink<Mutex> {
|
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
||||||
public:
|
textedit_p->append(str_v);
|
||||||
qplaintextedit_sink(QPlainTextEdit *textedit = nullptr) {
|
}
|
||||||
if (textedit != nullptr) {
|
|
||||||
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>(
|
void flush_() override {}
|
||||||
textedit);
|
|
||||||
} else {
|
private:
|
||||||
throw spdlog_ex("Error opening QPlainTextEdit");
|
std::shared_ptr<_spdlog_p::_sinks_p::qtextedit_sink_p> textedit_p = nullptr;
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
//
|
||||||
~qplaintextedit_sink() { flush_(); }
|
// qplaintextedit_sink class
|
||||||
|
//
|
||||||
protected:
|
template<typename Mutex>
|
||||||
void sink_it_(const details::log_msg &msg) override {
|
class qplaintextedit_sink : public base_sink<Mutex>
|
||||||
memory_buf_t formatted;
|
{
|
||||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
public:
|
||||||
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
qplaintextedit_sink(QPlainTextEdit *textedit = nullptr)
|
||||||
textedit_p->append(str_v);
|
{
|
||||||
}
|
if (textedit != nullptr)
|
||||||
|
{
|
||||||
void flush_() override {}
|
textedit_p = std::make_shared<_spdlog_p::_sinks_p::qplaintextedit_sink_p>(textedit);
|
||||||
|
}
|
||||||
private:
|
else
|
||||||
std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p =
|
{
|
||||||
nullptr;
|
throw spdlog_ex("Error opening QPlainTextEdit");
|
||||||
};
|
}
|
||||||
|
}
|
||||||
#include "spdlog/details/null_mutex.h"
|
|
||||||
#include <mutex>
|
~qplaintextedit_sink()
|
||||||
using qtextedit_sink_mt = qtextedit_sink<std::mutex>;
|
{
|
||||||
using qtextedit_sink_st = qtextedit_sink<spdlog::details::null_mutex>;
|
flush_();
|
||||||
|
}
|
||||||
using qplaintextedit_sink_mt = qplaintextedit_sink<std::mutex>;
|
|
||||||
using qplaintextedit_sink_st = qplaintextedit_sink<spdlog::details::null_mutex>;
|
protected:
|
||||||
|
void sink_it_(const details::log_msg &msg) override
|
||||||
} // namespace sinks
|
{
|
||||||
|
memory_buf_t formatted;
|
||||||
//
|
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||||
// Factory functions
|
string_view_t str_v = string_view_t(formatted.data(), formatted.size());
|
||||||
//
|
textedit_p->append(str_v);
|
||||||
template <typename Factory = spdlog::synchronous_factory>
|
}
|
||||||
inline std::shared_ptr<logger>
|
|
||||||
qtextedit_logger_mt(const std::string &logger_name,
|
void flush_() override {}
|
||||||
QTextEdit *qtextedit = nullptr) {
|
|
||||||
return Factory::template create<sinks::qtextedit_sink_mt>(logger_name,
|
private:
|
||||||
qtextedit);
|
std::shared_ptr<_spdlog_p::_sinks_p::qplaintextedit_sink_p> textedit_p = nullptr;
|
||||||
}
|
};
|
||||||
|
|
||||||
template <typename Factory = spdlog::synchronous_factory>
|
#include "spdlog/details/null_mutex.h"
|
||||||
inline std::shared_ptr<logger>
|
#include <mutex>
|
||||||
qtextedit_logger_st(const std::string &logger_name,
|
using qtextedit_sink_mt = qtextedit_sink<std::mutex>;
|
||||||
QTextEdit *qtextedit = nullptr) {
|
using qtextedit_sink_st = qtextedit_sink<spdlog::details::null_mutex>;
|
||||||
return Factory::template create<sinks::qtextedit_sink_st>(logger_name,
|
|
||||||
qtextedit);
|
using qplaintextedit_sink_mt = qplaintextedit_sink<std::mutex>;
|
||||||
}
|
using qplaintextedit_sink_st = qplaintextedit_sink<spdlog::details::null_mutex>;
|
||||||
|
|
||||||
template <typename Factory = spdlog::synchronous_factory>
|
} // namespace sinks
|
||||||
inline std::shared_ptr<logger>
|
|
||||||
qplaintextedit_logger_mt(const std::string &logger_name,
|
//
|
||||||
QPlainTextEdit *qplaintextedit = nullptr) {
|
// Factory functions
|
||||||
return Factory::template create<sinks::qplaintextedit_sink_mt>(
|
//
|
||||||
logger_name, qplaintextedit);
|
template<typename Factory = spdlog::synchronous_factory>
|
||||||
}
|
inline std::shared_ptr<logger> qtextedit_logger_mt(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
|
||||||
|
{
|
||||||
template <typename Factory = spdlog::synchronous_factory>
|
return Factory::template create<sinks::qtextedit_sink_mt>(logger_name, qtextedit);
|
||||||
inline std::shared_ptr<logger>
|
}
|
||||||
qplaintextedit_logger_st(const std::string &logger_name,
|
|
||||||
QPlainTextEdit *qplaintextedit = nullptr) {
|
template<typename Factory = spdlog::synchronous_factory>
|
||||||
return Factory::template create<sinks::qplaintextedit_sink_st>(
|
inline std::shared_ptr<logger> qtextedit_logger_st(const std::string &logger_name, QTextEdit *qtextedit = nullptr)
|
||||||
logger_name, qplaintextedit);
|
{
|
||||||
}
|
return Factory::template create<sinks::qtextedit_sink_st>(logger_name, qtextedit);
|
||||||
} // namespace spdlog
|
}
|
||||||
|
|
||||||
|
template<typename Factory = spdlog::synchronous_factory>
|
||||||
|
inline std::shared_ptr<logger> qplaintextedit_logger_mt(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
|
||||||
|
{
|
||||||
|
return Factory::template create<sinks::qplaintextedit_sink_mt>(logger_name, qplaintextedit);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Factory = spdlog::synchronous_factory>
|
||||||
|
inline std::shared_ptr<logger> qplaintextedit_logger_st(const std::string &logger_name, QPlainTextEdit *qplaintextedit = nullptr)
|
||||||
|
{
|
||||||
|
return Factory::template create<sinks::qplaintextedit_sink_st>(logger_name, qplaintextedit);
|
||||||
|
}
|
||||||
|
} // namespace spdlog
|
||||||
|
Loading…
Reference in New Issue