QuasarAppLib
qalogger.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2025 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#include "qalogger.h"
9#include "params.h"
10
11#include <QFile>
12
13namespace QuasarAppUtils {
14
15
16#define MESSAGE_PATTERN \
17 "[%{time MM-dd h:mm:ss.zzz} %{threadid} " \
18 "%{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] " \
19 "%{message}"
20
21
23 switch (type) {
24 case QtDebugMsg: return lvl >= Debug;
25 case QtInfoMsg: return lvl >= Info;
26 case QtWarningMsg: return lvl >= Warning;
27
28 case QtCriticalMsg:
29 case QtFatalMsg:
30 return true;
31 }
32
33 return true;
34}
36
37 if (Params::isEndable("fileLog")) {
38 auto verboselvl = Params::getVerboseLvl();
40 QString path = Params::getCurrentExecutable() + ".log";
41 auto file = Params::getArg("fileLog");
42 if (file.size()) {
43 path = file;
44 }
45
47 if (logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
48
50#if QT_VERSION > QT_VERSION_CHECK(5, 14, 0)
51 stream << msg << Qt::endl;
52#else
53 stream << msg << endl;
54#endif
55 logFile.close();
56 }
57 }
58 }
59}
60
66
67}
void init()
init This method initialize logging of all qt message into file.
Definition qalogger.cpp:61
The QuasaraAppUtils class This lib include base functions for the all applications of QuasarApp group...
Definition helpdata.cpp:18
void messageHandler(QtMsgType type, const QMessageLogContext &, const QString &msg)
Definition qalogger.cpp:35
bool checkLogType(QtMsgType type, VerboseLvl lvl)
Definition qalogger.cpp:22
VerboseLvl
The VerboseLvl enum uses for sets log level.
Definition params.h:23
@ Warning
Warning message. This logs will marked as a Warning and printing if the verbose lvl >= 1.
Definition params.h:27
@ Info
General information. This logs will marked as a Info and and printing if the verbose lvl >= 2.
Definition params.h:29
@ Debug
Debug message. This logs will marked as a Debug and printing if the verbose lvl >= 3.
Definition params.h:31
void gen(int size, QByteArray &result)
#define MESSAGE_PATTERN
Definition qalogger.cpp:16