5 #include <QApplication>
7 #if !TTK_QT_VERSION_CHECK(5,0,0)
10 #define qInstallMessageHandler qInstallMsgHandler
46 #if TTK_QT_VERSION_CHECK(5,0,0)
49 static void loggerHandler(QtMsgType type,
const char *message);
69 void save(
const QString &message);
87 m_maxSize(5 * 1024 * 1024),
88 m_maxSecond(7 * 24 * 3600),
92 m_outputDir(QString::fromLocal8Bit(qgetenv(
"APPDATA")) +
TTK_SEPARATOR +
"ttk/"),
94 m_outputDir(QDir::homePath() +
TTK_SEPARATOR +
".config/ttk/"),
97 m_defaultHandler(nullptr)
112 if(!module.isEmpty())
125 for(
const QFileInfo &fin : dir.entryInfoList())
127 const QString &fileName = fin.fileName();
128 if(fileName ==
"." || fileName ==
".." || fin.suffix() !=
"log")
133 #if TTK_QT_VERSION_CHECK(5,10,0)
134 const qint64 old = fin.birthTime().toMSecsSinceEpoch();
136 const qint64 old = fin.created().toMSecsSinceEpoch();
138 const qint64 current = QDateTime::currentMSecsSinceEpoch();
139 if((current - old) / 1000 > time)
141 QFile::remove(fin.absoluteFilePath());
186 m_maxSecond = maxSecond;
194 #if TTK_QT_VERSION_CHECK(5,0,0)
219 m_file.setFileName(fileName + QString(
"_%1.log").arg(index++));
223 if(!
m_file.open(QIODevice::WriteOnly | QIODevice::Append))
247 #if TTK_QT_VERSION_CHECK(5,5,0)
248 if(type == QtDebugMsg || type == QtWarningMsg || type == QtInfoMsg)
250 if(type == QtDebugMsg || type == QtWarningMsg)
253 QTextStream(stdout) << message <<
QtNamespace(endl);
257 QTextStream(stderr) << message <<
QtNamespace(endl);
265 const bool nextDate = date.compare(
m_dateTime, Qt::CaseInsensitive) != 0;
267 if(moreLarge || nextDate)
static QString message(const TTK::Attribute attr)
void setMaxSize(size_t maxSize) noexcept
TTK_MODULE_EXPORT void setOutputPath(const QString &dir)
#define qInstallMessageHandler
void save(const QString &message)
TTK_MODULE_EXPORT void initiailizeLog(const QString &module)
static void removeFiles(const QString &path, const qint64 time)
TTK_MODULE_EXPORT void installLogHandler()
QtMsgHandler QtMessageHandler
TTK_MODULE_EXPORT void removeLogHandler()
#define TTK_DECLARE_SINGLETON_CLASS(Class)
// Singleton Macro // //
void write(QtMsgType type, const QMessageLogContext &context, const QString &message)
#define QtNamespace(p)
Qt use namespace.
void initialize(const QString &module)
void setOutputPath(const QString &dir) noexcept
QtMessageHandler m_defaultHandler
static void loggerHandler(QtMsgType type, const char *message)
#define TTK_ERROR_STREAM(msg)
TTK_MODULE_EXPORT void setLogMaxSize(qint64 maxSize)
void setExpireSecond(size_t maxSecond) noexcept
TTK_MODULE_EXPORT void setExpireSecond(qint64 maxSecond)