feature:log4qt日志信息中增加进程ID信息;fix:修复log4qt偶现释放资源时卡住导致进程无法正常结束问题

This commit is contained in:
winnerym100
2021-06-11 19:44:43 +08:00
parent f4f5a84fc7
commit 20bd87519c
4 changed files with 18 additions and 62 deletions
+9
View File
@@ -1,3 +1,12 @@
ukui-interface (1.0.1-9hw1) v101.hw; urgency=medium
* BUG号:无
* 需求号:无
* 其他改动说明:1、修复log4qt日志库偶现释放资源时因等待线程退出阻塞进程退出问题;
2、辅助修复55965、59160bug中ukui-session偶现卡住问题
-- Yang Min <yangmin@kylinos.cn> Fri, 11 Jun 2021 19:34:53 +0800
ukui-interface (1.0.1-8) v101; urgency=medium
* BUG号:无
+6 -5
View File
@@ -54,6 +54,7 @@
#include "log4qt/varia/denyallfilter.h"
#include "log4qt/varia/levelrangefilter.h"
#include <unistd.h>
namespace Log4Qt
{
@@ -415,9 +416,9 @@ namespace Log4Qt
#endif
#if defined(Q_OS_UNIX) && defined(QT_DEBUG)
abort(); // trap; generates core dump
//abort(); // trap; generates core dump
#else
exit(1); // goodbye cruel world
//exit(1); // goodbye cruel world
#endif
}
@@ -447,7 +448,7 @@ namespace Log4Qt
default:
level = Level::TRACE_INT;
}
QString newMsg = context.file?QString("%1:%2(%3)|").arg(context.file).arg(context.line).arg(context.function):"|";
QString newMsg = context.file?QString("|PID:%1|%2:%3(%4)|").arg(getpid()).arg(context.file).arg(context.line).arg(context.function):QString("|PID:%1|").arg(getpid());
instance()->qtLogger()->log(level, newMsg+message);
// Qt fatal behaviour copied from global.cpp qt_message_output()
@@ -468,9 +469,9 @@ namespace Log4Qt
#endif
#if defined(Q_OS_UNIX) && defined(QT_DEBUG)
abort(); // trap; generates core dump
//abort(); // trap; generates core dump
#else
exit(1); // goodbye cruel world
//exit(1); // goodbye cruel world
#endif
}
+3 -54
View File
@@ -66,9 +66,7 @@ namespace Log4Qt
AppenderSkeleton(false, pParent),
mpEncoding(0),
mpWriter(0),
mImmediateFlush(true),
mThread(nullptr),
mAsyncDispatcher(nullptr)
mImmediateFlush(true)
{
}
@@ -78,9 +76,7 @@ namespace Log4Qt
AppenderSkeleton(false, pParent),
mpEncoding(0),
mpWriter(0),
mImmediateFlush(true),
mThread(nullptr),
mAsyncDispatcher(nullptr)
mImmediateFlush(true)
{
setLayout(pLayout);
}
@@ -92,9 +88,7 @@ namespace Log4Qt
AppenderSkeleton(false, pParent),
mpEncoding(0),
mpWriter(pTextStream),
mImmediateFlush(true),
mThread(nullptr),
mAsyncDispatcher(nullptr)
mImmediateFlush(true)
{
setLayout(pLayout);
}
@@ -151,15 +145,6 @@ namespace Log4Qt
}
AppenderSkeleton::activateOptions();
if (mThread != nullptr)
return;
mThread = new QThread();
mAsyncDispatcher = new AsyncDispatcher();
mAsyncDispatcher->setAsyncAppender(this);
mAsyncDispatcher->moveToThread(mThread);
//mThread->start();
}
@@ -179,17 +164,6 @@ namespace Log4Qt
{
if (isClosed())
return;
if (mThread != nullptr)
{
mAsyncDispatcher->setAsyncAppender(nullptr);
mThread->quit();
mThread->wait();
delete mThread;
mThread = nullptr;
delete mAsyncDispatcher;
mAsyncDispatcher = nullptr;
}
}
bool WriterAppender::requiresLayout() const
@@ -201,7 +175,6 @@ namespace Log4Qt
void WriterAppender::append(const LoggingEvent &rEvent)
{
// Q_ASSERT_X(, "WriterAppender::append()", "Lock must be held by caller");
#ifndef UKUILOG4QT_EXTRA_ENABLE
Q_ASSERT_X(layout(), "WriterAppender::append()", "Layout must not be null");
QString message(layout()->format(rEvent));
@@ -218,30 +191,6 @@ namespace Log4Qt
if (handleIoErrors())
return;
}
#else
if (qApp && g_MainProcPid == getpid()) {
if (mThread && !mThread->isRunning())
mThread->start();
qApp->postEvent(mAsyncDispatcher, new LoggingEvent(rEvent));
} else {
Q_ASSERT_X(layout(), "WriterAppender::append()", "Layout must not be null");
QString message(layout()->format(rEvent));
if (!mpWriter)
return;
*mpWriter << message;
if (handleIoErrors())
return;
if (immediateFlush())
{
mpWriter->flush();
if (handleIoErrors())
return;
}
}
#endif
}
void WriterAppender::asyncAppend(const LoggingEvent &rEvent)
-3
View File
@@ -166,9 +166,6 @@ namespace Log4Qt
QTextCodec *mpEncoding;
QTextStream *mpWriter;
volatile bool mImmediateFlush;
//! Event dispatcher trhead
QThread *mThread;
AsyncDispatcher *mAsyncDispatcher;
};