Commit 6d62c4de authored by captainwong's avatar captainwong

update qt log

parent e01f174b
......@@ -28,6 +28,8 @@ public:
#else // JLIB_DISABLE_LOG
#define JLIB_LOG2_ENABLED
#include <iostream>
#include "3rdparty/spdlog/spdlog.h"
......@@ -43,7 +45,7 @@ public:
namespace jlib {
static const char g_logger_name[] = "jlogger";
static constexpr char g_logger_name[] = "jlogger";
inline void init_logger(const std::wstring& file_name = L"")
{
......
......@@ -11,3 +11,42 @@
#define MYQDEBUG qDebug() << QDEBUG_FILE_LINE_STREAM
#define MYQWARN qWarning() << QDEBUG_FILE_LINE_STREAM
#define MYQCRITICAL qCritical() << QDEBUG_FILE_LINE_STREAM
// if not defined, disable redirect
// if defined, you must include log2.h before include this file
#define REDIRECT_QT_OUTPUT_TO_LOG
#ifdef REDIRECT_QT_OUTPUT_TO_LOG
#ifndef JLIB_LOG2_ENABLED
#error 'You must include <jlib/log2.h> first!'
#else // has JLIB_LOG2_ENABLED
static inline void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
using namespace jlib;
QByteArray localMsg = msg.toLocal8Bit();
switch (type) {
case QtDebugMsg:
JLOG_INFO(localMsg.data());
break;
case QtWarningMsg:
if (!msg.contains("libpng")) {
JLOG_WARN(localMsg.data());
}
break;
case QtCriticalMsg:
JLOG_CRTC(localMsg.data());
break;
case QtFatalMsg:
JLOG_ERRO(localMsg.data());
break;
case QtInfoMsg:
JLOG_INFO(localMsg.data());
break;
default:
JLOG_WARN(localMsg.data());
break;
}
}
#endif // JLIB_LOG2_ENABLED
#endif // REDIRECT_QT_OUTPUT_TO_LOG
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment