13#include "private/standarddirs_p.h"
19#include <QLoggingCategory>
31 : mType(QtCriticalMsg)
36 bool isSequential()
const override
40 qint64 readData(
char * , qint64 )
override
44 qint64 readLineData(
char * , qint64 )
override
49 qint64 writeData(
const char *data, qint64 len)
override
51 if (!mFileName.isEmpty()) {
52 QFile outputFile(mFileName);
54 outputFile.write(data, len);
55 outputFile.putChar(
'\n');
62 void setFileName(
const QString &fileName)
67 void setType(QtMsgType type)
81 : origHandler(nullptr)
87 qInstallMessageHandler(origHandler);
91 static QString errorLogFileName(
const QString &name)
93 return Akonadi::StandardDirs::saveDir(
"data") +
QDir::separator() + name + QLatin1StringView(
".error");
96 QString errorLogFileName()
const
98 return errorLogFileName(name);
101 void log(QtMsgType type,
const QMessageLogContext &context,
const QString &msg)
103 QMutexLocker locker(&mutex);
104#ifdef QT_NO_DEBUG_OUTPUT
105 if (type == QtDebugMsg) {
110 QTextStream str(&buf);
129 str <<
"] " << context.category <<
": ";
130 if (context.file && *context.file && context.line) {
131 str << context.file <<
":" << context.line <<
": ";
133 if (context.function && *context.function) {
134 str << context.function <<
": ";
142 origHandler(type, context, msg);
146 void setName(
const QString &appName)
153 QFileInfo finfo(errorLogFileName());
154 if (!finfo.absoluteDir().exists()) {
155 QDir().mkpath(finfo.absolutePath());
157 file.setFileName(errorLogFileName());
161 void setOrigHandler(QtMessageHandler origHandler_)
163 origHandler = origHandler_;
168 origFilter = origFilter_;
174 QtMessageHandler origHandler;
176 QByteArray loggingCategory;
179Q_GLOBAL_STATIC(DebugPrivate, sInstance)
188 sInstance()->log(type, context, msg);
191 sInstance()->log(QtInfoMsg, context, msg);
198 if ((qstrcmp(
category->categoryName(), sInstance()->loggingCategory.constData()) == 0)
199 || (qstrcmp(
category->categoryName(),
"org.kde.pim.akonadiprivate") == 0)) {
200 category->setEnabled(QtDebugMsg,
true);
201 category->setEnabled(QtInfoMsg,
true);
202 category->setEnabled(QtWarningMsg,
true);
203 category->setEnabled(QtCriticalMsg,
true);
204 category->setEnabled(QtFatalMsg,
true);
205 }
else if (sInstance()->origFilter) {
206 sInstance()->origFilter(category);
210void akInit(
const QString &appName)
215 const auto errorLogFile = DebugPrivate::errorLogFileName(name);
217 if (infoOld.exists()) {
218 QFile fileOld(infoOld.absoluteFilePath());
219 const bool success = fileOld.remove();
221 qFatal(
"Cannot remove old log file '%s': %s", qUtf8Printable(fileOld.fileName()), qUtf8Printable(fileOld.errorString()));
227 QFile file(info.absoluteFilePath());
229 const bool success = file.copy(oldName);
231 qFatal(
"Cannot rename log file '%s' to '%s': %s", qUtf8Printable(file.fileName()), qUtf8Printable(oldName), qUtf8Printable(file.errorString()));
235 QtMessageHandler origHandler = qInstallMessageHandler(akMessageHandler);
236 sInstance()->setName(name);
237 sInstance()->setOrigHandler(origHandler);
242 sInstance()->loggingCategory =
category;
244 sInstance()->setOrigCategoryFilter(oldFilter);
247#include "akdebug.moc"
Q_SCRIPTABLE Q_NOREPLY void abort()
KCRASH_EXPORT void initialize()
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QString name(StandardAction id)
Category category(StandardShortcut id)
QCA_EXPORT QString appName()
const char * constData() const const
qsizetype size() const const
QDateTime currentDateTime()
QString toString(QStringView format, QCalendar cal) const const
QString fileName() const const
virtual bool open(QIODeviceBase::OpenMode mode)
CategoryFilter installFilter(CategoryFilter filter)