|
|
|
@ -11,7 +11,7 @@
|
|
|
|
|
// auto edit = new QTextEdit();
|
|
|
|
|
// setCentralWidget(edit);
|
|
|
|
|
// auto logger = spdlog::qt_color_logger_mt("my_logger", my_edit_widget);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Warning: those sinks won't be notified if the target widget is destroyed.
|
|
|
|
|
// If the widget's lifetime can be shorter than the logger's one, you should provide some permanent QObject,
|
|
|
|
|
// and then use a standard signal/slot.
|
|
|
|
@ -72,7 +72,6 @@ private:
|
|
|
|
|
QMetaMethod meta_method_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// QT color sink to QTextEdit.
|
|
|
|
|
// Color location is determined by the sink log pattern like in the rest of spdlog sinks.
|
|
|
|
|
// Colors can be modified if needed using sink->set_color(level, qtTextCharFormat).
|
|
|
|
@ -81,7 +80,8 @@ template<typename Mutex>
|
|
|
|
|
class qt_color_sink : public base_sink<Mutex>
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
qt_color_sink(QTextEdit *qt_text_edit) : qt_text_edit_(qt_text_edit)
|
|
|
|
|
qt_color_sink(QTextEdit *qt_text_edit)
|
|
|
|
|
: qt_text_edit_(qt_text_edit)
|
|
|
|
|
{
|
|
|
|
|
if (!qt_text_edit_)
|
|
|
|
|
{
|
|
|
|
@ -177,7 +177,6 @@ protected:
|
|
|
|
|
QTextEdit *qt_text_edit_;
|
|
|
|
|
QTextCharFormat default_color_;
|
|
|
|
|
std::array<QTextCharFormat, level::n_levels> colors_;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#include "spdlog/details/null_mutex.h"
|
|
|
|
@ -194,13 +193,15 @@ using qt_color_sink_st = qt_color_sink<spdlog::details::null_mutex>;
|
|
|
|
|
|
|
|
|
|
// create logger using QTextEdit object
|
|
|
|
|
template<typename Factory = spdlog::synchronous_factory>
|
|
|
|
|
inline std::shared_ptr<logger> qt_logger_mt(const std::string &logger_name, QTextEdit *qt_object, const std::string &meta_method = "append(QString)")
|
|
|
|
|
inline std::shared_ptr<logger> qt_logger_mt(
|
|
|
|
|
const std::string &logger_name, QTextEdit *qt_object, const std::string &meta_method = "append(QString)")
|
|
|
|
|
{
|
|
|
|
|
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, QTextEdit *qt_object, const std::string &meta_method = "append(QString)")
|
|
|
|
|
inline std::shared_ptr<logger> qt_logger_st(
|
|
|
|
|
const std::string &logger_name, QTextEdit *qt_object, const std::string &meta_method = "append(QString)")
|
|
|
|
|
{
|
|
|
|
|
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
|
|
|
|
}
|
|
|
|
|