12#include <QCoreApplication>
14#include <QStandardPaths>
18static QFile* _logFile;
19static bool _toFile =
false;
23#define MESSAGE_PATTERN \
24"[%{time MM-dd h:mm:ss.zzz} %{threadid} " \
25 "%{if-debug}Debug%{endif}%{if-info}Info%{endif}%{if-warning}Warning%{endif}%{if-critical}Error%{endif}%{if-fatal}Fatal%{endif}] " \
30 _logFile =
new QFile();
57 if (_toFile && _logFile) {
64 case QtMsgType::QtFatalMsg: {
69 case QtMsgType::QtCriticalMsg:
70 case QtMsgType::QtWarningMsg: {
74 case QtMsgType::QtDebugMsg:
75 case QtMsgType::QtInfoMsg:
92 _verboseLevel = Params::getVerboseLvl();
94 if (Params::isEndable(
"fileLog")) {
96 QString path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) +
"/" + QCoreApplication::applicationName() +
".log";
97 auto file = Params::getArg(
"fileLog");
102 _logFile->setFileName(
path);
104 if (!_logFile->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
105 qFatal() <<
"Can't open log file";
void init()
init This method initialize logging of all qt message into file.
The QuasaraAppUtils class This lib include base functions for the all applications of QuasarApp group...
bool checkLogType(QtMsgType type, VerboseLvl lvl)
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
VerboseLvl
The VerboseLvl enum uses for sets log level.
@ Warning
Warning message. This logs will marked as a Warning and printing if the verbose lvl >= 1.
@ Info
General information. This logs will marked as a Info and and printing if the verbose lvl >= 2.
@ Debug
Debug message. This logs will marked as a Debug and printing if the verbose lvl >= 3.
void gen(int size, QByteArray &result)