mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 10:52:49 +00:00
kdecore: deal with TODO related to KDebug
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
a1a03f11a0
commit
054f2fc7e7
1 changed files with 54 additions and 14 deletions
|
@ -139,11 +139,14 @@ class KDebugFileDevice: public KDebugNullDevice
|
||||||
public:
|
public:
|
||||||
KDebugFileDevice()
|
KDebugFileDevice()
|
||||||
: m_type(QtDebugMsg),
|
: m_type(QtDebugMsg),
|
||||||
|
m_abortfatal(true),
|
||||||
m_filepath(s_kdebugfilepath)
|
m_filepath(s_kdebugfilepath)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void setType(const QtMsgType type)
|
void setType(const QtMsgType type)
|
||||||
{ m_type = type; }
|
{ m_type = type; }
|
||||||
|
void setAbortFatal(const bool abortfatal)
|
||||||
|
{ m_abortfatal = abortfatal; }
|
||||||
void setHeader(const QByteArray &header)
|
void setHeader(const QByteArray &header)
|
||||||
{ m_header = header; }
|
{ m_header = header; }
|
||||||
void setFilepath(const QString &filepath)
|
void setFilepath(const QString &filepath)
|
||||||
|
@ -154,19 +157,26 @@ protected:
|
||||||
{
|
{
|
||||||
QFile writefile(m_filepath);
|
QFile writefile(m_filepath);
|
||||||
if (!writefile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Unbuffered)) {
|
if (!writefile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Unbuffered)) {
|
||||||
|
if (m_abortfatal && m_type == QtFatalMsg) {
|
||||||
|
::abort();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// TODO: m_type
|
// TODO: insert type somewhere
|
||||||
writefile.write(m_header.constData(), m_header.size());
|
writefile.write(m_header.constData(), m_header.size());
|
||||||
writefile.write(": ", 2);
|
writefile.write(": ", 2);
|
||||||
writefile.write(data, len);
|
writefile.write(data, len);
|
||||||
writefile.write("\n", 1);
|
writefile.write("\n", 1);
|
||||||
|
if (m_abortfatal && m_type == QtFatalMsg) {
|
||||||
|
::abort();
|
||||||
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(KDebugFileDevice);
|
Q_DISABLE_COPY(KDebugFileDevice);
|
||||||
QtMsgType m_type;
|
QtMsgType m_type;
|
||||||
|
bool m_abortfatal;
|
||||||
QByteArray m_header;
|
QByteArray m_header;
|
||||||
QString m_filepath;
|
QString m_filepath;
|
||||||
};
|
};
|
||||||
|
@ -176,11 +186,14 @@ class KDebugMessageBoxDevice: public KDebugNullDevice
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
KDebugMessageBoxDevice()
|
KDebugMessageBoxDevice()
|
||||||
: m_type(QtDebugMsg)
|
: m_type(QtDebugMsg),
|
||||||
|
m_abortfatal(true)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void setType(const QtMsgType type)
|
void setType(const QtMsgType type)
|
||||||
{ m_type = type; }
|
{ m_type = type; }
|
||||||
|
void setAbortFatal(const bool abortfatal)
|
||||||
|
{ m_abortfatal = abortfatal; }
|
||||||
void setHeader(const QByteArray &header)
|
void setHeader(const QByteArray &header)
|
||||||
{ m_header = header; }
|
{ m_header = header; }
|
||||||
|
|
||||||
|
@ -206,6 +219,12 @@ protected:
|
||||||
}
|
}
|
||||||
case QtFatalMsg: {
|
case QtFatalMsg: {
|
||||||
KMessage::message(KMessage::Fatal, text);
|
KMessage::message(KMessage::Fatal, text);
|
||||||
|
if (m_abortfatal) {
|
||||||
|
// can't show message box and abort immediately, note that depending on the
|
||||||
|
// KMessage handler and the alarm() behaviour (man 2 alarm) a lot of bad things
|
||||||
|
// can happen meanwhile
|
||||||
|
::alarm(10);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,7 +233,8 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(KDebugMessageBoxDevice);
|
Q_DISABLE_COPY(KDebugMessageBoxDevice);
|
||||||
int m_type;
|
QtMsgType m_type;
|
||||||
|
bool m_abortfatal;
|
||||||
QByteArray m_header;
|
QByteArray m_header;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -223,11 +243,14 @@ class KDebugShellDevice: public KDebugNullDevice
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
KDebugShellDevice()
|
KDebugShellDevice()
|
||||||
: m_type(QtDebugMsg)
|
: m_type(QtDebugMsg),
|
||||||
|
m_abortfatal(true)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void setType(const QtMsgType type)
|
void setType(const QtMsgType type)
|
||||||
{ m_type = type; }
|
{ m_type = type; }
|
||||||
|
void setAbortFatal(const bool abortfatal)
|
||||||
|
{ m_abortfatal = abortfatal; }
|
||||||
void setHeader(const QByteArray &header)
|
void setHeader(const QByteArray &header)
|
||||||
{ m_header = header; }
|
{ m_header = header; }
|
||||||
|
|
||||||
|
@ -262,6 +285,9 @@ protected:
|
||||||
case QtFatalMsg: {
|
case QtFatalMsg: {
|
||||||
::fprintf(stderr, "\033[0;5;31m%s: %s\033[0m\n", m_header.constData(), data);
|
::fprintf(stderr, "\033[0;5;31m%s: %s\033[0m\n", m_header.constData(), data);
|
||||||
::fflush(stderr);
|
::fflush(stderr);
|
||||||
|
if (m_abortfatal) {
|
||||||
|
::abort();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,12 +297,16 @@ protected:
|
||||||
|
|
||||||
::fprintf(stderr, "%s: %s\n", m_header.constData(), data);
|
::fprintf(stderr, "%s: %s\n", m_header.constData(), data);
|
||||||
::fflush(stderr);
|
::fflush(stderr);
|
||||||
|
if (m_abortfatal && m_type == QtFatalMsg) {
|
||||||
|
::abort();
|
||||||
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(KDebugShellDevice);
|
Q_DISABLE_COPY(KDebugShellDevice);
|
||||||
int m_type;
|
QtMsgType m_type;
|
||||||
|
bool m_abortfatal;
|
||||||
QByteArray m_header;
|
QByteArray m_header;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -285,12 +315,15 @@ class KDebugSyslogDevice: public KDebugNullDevice
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
KDebugSyslogDevice(const QByteArray &areaname)
|
KDebugSyslogDevice(const QByteArray &areaname)
|
||||||
: m_type(LOG_INFO),
|
: m_type(QtDebugMsg),
|
||||||
|
m_abortfatal(true),
|
||||||
m_areaname(areaname)
|
m_areaname(areaname)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void setType(const QtMsgType type)
|
void setType(const QtMsgType type)
|
||||||
{ m_type = type; }
|
{ m_type = type; }
|
||||||
|
void setAbortFatal(const bool abortfatal)
|
||||||
|
{ m_abortfatal = abortfatal; }
|
||||||
void setHeader(const QByteArray &header)
|
void setHeader(const QByteArray &header)
|
||||||
{ m_header = header; }
|
{ m_header = header; }
|
||||||
|
|
||||||
|
@ -317,12 +350,16 @@ protected:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
::closelog();
|
::closelog();
|
||||||
|
if (m_abortfatal && m_type == QtFatalMsg) {
|
||||||
|
::abort();
|
||||||
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(KDebugSyslogDevice);
|
Q_DISABLE_COPY(KDebugSyslogDevice);
|
||||||
int m_type;
|
QtMsgType m_type;
|
||||||
|
bool m_abortfatal;
|
||||||
QByteArray m_header;
|
QByteArray m_header;
|
||||||
QByteArray m_areaname;
|
QByteArray m_areaname;
|
||||||
};
|
};
|
||||||
|
@ -361,8 +398,8 @@ public:
|
||||||
void cacheAreas();
|
void cacheAreas();
|
||||||
|
|
||||||
bool disableAll() const;
|
bool disableAll() const;
|
||||||
QByteArray areaName(const int number) const;
|
QByteArray areaName(const int area) const;
|
||||||
KDebugAreaCache areaCache(const int number) const;
|
KDebugAreaCache areaCache(const int area) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(KDebugConfig);
|
Q_DISABLE_COPY(KDebugConfig);
|
||||||
|
@ -437,9 +474,9 @@ bool KDebugConfig::disableAll() const
|
||||||
return m_disableall;
|
return m_disableall;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray KDebugConfig::areaName(const int number) const
|
QByteArray KDebugConfig::areaName(const int area) const
|
||||||
{
|
{
|
||||||
const QByteArray areaname = m_areanames.value(number);
|
const QByteArray areaname = m_areanames.value(area);
|
||||||
if (!areaname.isEmpty()) {
|
if (!areaname.isEmpty()) {
|
||||||
return areaname;
|
return areaname;
|
||||||
}
|
}
|
||||||
|
@ -450,9 +487,9 @@ QByteArray KDebugConfig::areaName(const int number) const
|
||||||
return QCoreApplication::applicationName().toUtf8();
|
return QCoreApplication::applicationName().toUtf8();
|
||||||
}
|
}
|
||||||
|
|
||||||
KDebugAreaCache KDebugConfig::areaCache(const int number) const
|
KDebugAreaCache KDebugConfig::areaCache(const int area) const
|
||||||
{
|
{
|
||||||
return m_areacache.value(number);
|
return m_areacache.value(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString kBacktrace(int levels)
|
QString kBacktrace(int levels)
|
||||||
|
@ -510,7 +547,6 @@ QDebug KDebug(const QtMsgType type, const char* const funcinfo, const int area)
|
||||||
const KDebugAreaCache kdebugareacache = globalKDebugConfig->areaCache(area);
|
const KDebugAreaCache kdebugareacache = globalKDebugConfig->areaCache(area);
|
||||||
int areaoutput = int(KDebugType::TypeShell);
|
int areaoutput = int(KDebugType::TypeShell);
|
||||||
QString areafilename;
|
QString areafilename;
|
||||||
// TODO: abort when? can't show message box and abort immediately
|
|
||||||
bool areaabort = true;
|
bool areaabort = true;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QtDebugMsg: {
|
case QtDebugMsg: {
|
||||||
|
@ -546,6 +582,7 @@ QDebug KDebug(const QtMsgType type, const char* const funcinfo, const int area)
|
||||||
}
|
}
|
||||||
KDebugFileDevice* kdebugdevice = qobject_cast<KDebugFileDevice*>(qiodevice);
|
KDebugFileDevice* kdebugdevice = qobject_cast<KDebugFileDevice*>(qiodevice);
|
||||||
kdebugdevice->setType(type);
|
kdebugdevice->setType(type);
|
||||||
|
kdebugdevice->setAbortFatal(areaabort);
|
||||||
kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo, areaoutput));
|
kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo, areaoutput));
|
||||||
kdebugdevice->setFilepath(areafilename);
|
kdebugdevice->setFilepath(areafilename);
|
||||||
return QDebug(kdebugdevice);
|
return QDebug(kdebugdevice);
|
||||||
|
@ -558,6 +595,7 @@ QDebug KDebug(const QtMsgType type, const char* const funcinfo, const int area)
|
||||||
}
|
}
|
||||||
KDebugMessageBoxDevice* kdebugdevice = qobject_cast<KDebugMessageBoxDevice*>(qiodevice);
|
KDebugMessageBoxDevice* kdebugdevice = qobject_cast<KDebugMessageBoxDevice*>(qiodevice);
|
||||||
kdebugdevice->setType(type);
|
kdebugdevice->setType(type);
|
||||||
|
kdebugdevice->setAbortFatal(areaabort);
|
||||||
kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo, areaoutput));
|
kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo, areaoutput));
|
||||||
return QDebug(kdebugdevice);
|
return QDebug(kdebugdevice);
|
||||||
}
|
}
|
||||||
|
@ -569,6 +607,7 @@ QDebug KDebug(const QtMsgType type, const char* const funcinfo, const int area)
|
||||||
}
|
}
|
||||||
KDebugShellDevice* kdebugdevice = qobject_cast<KDebugShellDevice*>(qiodevice);
|
KDebugShellDevice* kdebugdevice = qobject_cast<KDebugShellDevice*>(qiodevice);
|
||||||
kdebugdevice->setType(type);
|
kdebugdevice->setType(type);
|
||||||
|
kdebugdevice->setAbortFatal(areaabort);
|
||||||
kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo, areaoutput));
|
kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo, areaoutput));
|
||||||
return QDebug(kdebugdevice);
|
return QDebug(kdebugdevice);
|
||||||
}
|
}
|
||||||
|
@ -580,6 +619,7 @@ QDebug KDebug(const QtMsgType type, const char* const funcinfo, const int area)
|
||||||
}
|
}
|
||||||
KDebugSyslogDevice* kdebugdevice = qobject_cast<KDebugSyslogDevice*>(qiodevice);
|
KDebugSyslogDevice* kdebugdevice = qobject_cast<KDebugSyslogDevice*>(qiodevice);
|
||||||
kdebugdevice->setType(type);
|
kdebugdevice->setType(type);
|
||||||
|
kdebugdevice->setAbortFatal(areaabort);
|
||||||
kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo, areaoutput));
|
kdebugdevice->setHeader(kDebugHeader(globalKDebugConfig->areaName(area), funcinfo, areaoutput));
|
||||||
return QDebug(kdebugdevice);
|
return QDebug(kdebugdevice);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue