Skip to content

Commit a21c8d3

Browse files
authored
Merge pull request #43 from QuasarApp/qt_logger
move to qt logger system
2 parents ad939ab + f82a69d commit a21c8d3

11 files changed

Lines changed: 134 additions & 164 deletions

CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ file(GLOB SOURCE_CPP
6363
"*.cpp" "*.h"
6464
)
6565

66-
add_library(${PROJECT_NAME} ${SOURCE_CPP}
67-
qasecretservice.h qasecretservice.cpp)
66+
add_library(${PROJECT_NAME} ${SOURCE_CPP})
6867
target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Core)
6968
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
7069

71-
setVersion(1 5 3)
70+
setVersion(1 5 4)
7271

7372
initAll()
7473
make_directory("${CMAKE_CURRENT_SOURCE_DIR}/Distro")

helpdata.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <windows.h>
1313
#else
1414
#include <sys/ioctl.h>
15-
#include <stdio.h>
1615
#include <unistd.h>
1716
#endif
1817

locales.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <QRegularExpression>
1616
#include <QLocale>
1717
#include <QMap>
18-
#include "params.h"
1918

2019
using namespace QuasarAppUtils;
2120

@@ -31,17 +30,15 @@ bool QuasarAppUtils::Locales::findQmPrivate(const QString &prefix,
3130
auto qmFile = new QTranslator();
3231

3332
if(!qmFile->load(file.absoluteFilePath())) {
34-
QuasarAppUtils::Params::log("Failed to load translation file : "
35-
+ file.absoluteFilePath(),
36-
QuasarAppUtils::Warning);
33+
qWarning() << "Failed to load translation file : "
34+
+ file.absoluteFilePath();
3735
delete qmFile;
3836
continue;
3937
}
4038

4139
if (qmFile->isEmpty()) {
42-
QuasarAppUtils::Params::log("Translation file is Empty: " +
43-
file.absoluteFilePath(),
44-
QuasarAppUtils::Debug);
40+
qDebug() << "Translation file is Empty: " +
41+
file.absoluteFilePath();
4542
delete qmFile;
4643
continue;
4744
}
@@ -51,7 +48,7 @@ bool QuasarAppUtils::Locales::findQmPrivate(const QString &prefix,
5148
auto message = QString("The target language (%0) and a choosed qm file (%1) "
5249
"is different, Loading will be skiped: ").
5350
arg(language, file.absoluteFilePath());
54-
QuasarAppUtils::Params::log(message, QuasarAppUtils::Debug);
51+
qDebug() << message;
5552

5653
delete qmFile;
5754
continue;
@@ -85,9 +82,7 @@ void QuasarAppUtils::Locales::installTranslations( QList<QTranslator *> &qmFiles
8582
for (const auto & translator: std::as_const(qmFiles)) {
8683
if (!QCoreApplication::installTranslator(translator)) {
8784

88-
QuasarAppUtils::Params::log("Failed to install translation file : " + translator->filePath(),
89-
QuasarAppUtils::Warning);
90-
85+
qWarning() << "Failed to install translation file : " + translator->filePath();
9186
delete translator;
9287
// we use a link of qmFiles so remove all invalid translations.
9388
qmFiles.removeAll(translator);

optiondata.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
#include "optiondata.h"
10-
#include "qaglobalutils.h"
1110

1211
namespace QuasarAppUtils{
1312

params.cpp

Lines changed: 22 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
#include <QVariantMap>
1010
#include <QDebug>
1111
#include <QFileInfo>
12-
#include <iostream>
1312
#include <QDateTime>
1413
#include <QCoreApplication>
15-
#include "qaglobalutils.h"
14+
#include <QtLogging>
1615

1716
#ifdef Q_OS_WIN
1817
#include "windows.h"
1918
#else
2019
#include <unistd.h>
21-
#include <limits.h>
2220
#endif
2321

2422
using namespace QuasarAppUtils;
@@ -35,66 +33,27 @@ bool Params::isEndable(const QString& key) {
3533

3634
void Params::log(const QString &log, VerboseLvl vLvl) {
3735

38-
writeLoginFile(log, vLvl);
39-
4036
auto lvl = getVerboseLvl();
4137
if (vLvl <= lvl) {
4238

4339
switch (vLvl) {
4440

4541
case VerboseLvl::Error:
46-
#ifdef Q_OS_WIN32
47-
std::cerr << QString{lvlToString(vLvl) + ": " + log}.toStdString() << std::endl;
48-
#else
49-
qCritical().noquote() << lvlToString(vLvl) + ": " + log;
50-
#endif
51-
52-
#ifdef QA_ASSERT_ON_ERROR
53-
#ifdef __GNUC__
54-
__builtin_trap();
55-
#else
56-
debug_assert(false, "You requested to throw assert in every error message."
57-
" See The ASSERT_ON_ERROR option in cmake config.");
58-
#endif
59-
60-
#endif
42+
qCritical().noquote() << log;
6143
break;
6244

6345
case VerboseLvl::Warning: {
64-
#ifdef Q_OS_WIN32
65-
std::cerr << QString{lvlToString(vLvl) + ": " + log}.toStdString() << std::endl;
66-
#else
67-
qWarning().noquote() << lvlToString(vLvl) + ": " + log;
68-
#endif
69-
70-
71-
#ifdef QA_ASSERT_ON_WARN
72-
#ifdef __GNUC__
73-
__builtin_trap();
74-
#else
75-
debug_assert(false, "You requested to throw assert in every warning message."
76-
" See The ASSERT_ON_ERROR option in cmake config.");
77-
#endif
78-
79-
#endif
46+
qWarning().noquote() << log;
8047
break;
8148
}
8249
case VerboseLvl::Debug: {
83-
#ifdef Q_OS_WIN32
84-
std::cout << QString{lvlToString(vLvl) + ": " + log}.toStdString() << std::endl;
85-
#else
86-
qDebug().noquote() << lvlToString(vLvl) + ": " + log;
87-
#endif
50+
qDebug().noquote() << log;
8851
break;
8952
}
9053

9154
case VerboseLvl::Info:
9255
default: {
93-
#ifdef Q_OS_WIN32
94-
std::cout << QString{lvlToString(vLvl) + ": " + log}.toStdString() << std::endl;
95-
#else
96-
qInfo().noquote() << lvlToString(vLvl) + ": " + log;
97-
#endif
56+
qInfo().noquote() << log;
9857
break;
9958
}
10059

@@ -191,65 +150,6 @@ int Params::size() {
191150
return params.size();
192151
}
193152

194-
QString Params::timeString() {
195-
return QDateTime::currentDateTime().toString();
196-
}
197-
198-
QString Params::lvlToString(VerboseLvl vLvl) {
199-
switch (vLvl) {
200-
201-
case VerboseLvl::Error: {
202-
return "Error";
203-
}
204-
205-
case VerboseLvl::Warning: {
206-
return "Warning";
207-
}
208-
209-
case VerboseLvl::Info: {
210-
return "Info";
211-
}
212-
213-
case VerboseLvl::Debug: {
214-
return "Verbose log";
215-
}
216-
default: return "";
217-
}
218-
219-
return "";
220-
}
221-
222-
bool Params::writeLoginFile(const QString &log, VerboseLvl vLvl) {
223-
if (isEndable("fileLog")) {
224-
225-
auto lvl = getVerboseLvl();
226-
if (vLvl <= lvl) {
227-
QString path = getCurrentExecutable() + ".log";
228-
auto file = getArg("fileLog");
229-
if (file.size()) {
230-
path = file;
231-
}
232-
233-
QFile logFile(path);
234-
235-
if (logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
236-
237-
QTextStream stream(&logFile);
238-
#if QT_VERSION > QT_VERSION_CHECK(5, 14, 0)
239-
stream << timeString() <<"| " << lvlToString(vLvl) + ": " + log << Qt::endl;
240-
#else
241-
stream << timeString() <<"| " << lvlToString(vLvl) + ": " + log << endl;
242-
#endif
243-
logFile.close();
244-
} else {
245-
return false;
246-
}
247-
}
248-
}
249-
250-
return true;
251-
}
252-
253153
bool Params::optionsForEach(const QStringList &paramsArray,
254154
const OptionsDataList& availableOptions) {
255155

@@ -274,8 +174,7 @@ bool Params::optionsForEach(const QStringList &paramsArray,
274174
params[paramsArray[i].mid(1)] = paramsArray[i + 1];
275175
i++;
276176
} else {
277-
QuasarAppUtils::Params::log("Missing argument for " + paramsArray[i],
278-
QuasarAppUtils::Error);
177+
qCritical() << "Missing argument for " + paramsArray[i];
279178
return false;
280179
}
281180
} else {
@@ -322,8 +221,7 @@ bool Params::parseParams(const QStringList &paramsArray, const OptionsDataList &
322221
memset(path, 0, sizeof path);
323222

324223
if (readlink("/proc/self/exe", path, 2048) < 0) {
325-
QuasarAppUtils::Params::log("parseParams can't get self path!",
326-
QuasarAppUtils::Error);
224+
qCritical() << "parseParams can't get self path!";
327225
return false;
328226
}
329227
appPath = QFileInfo(path).absolutePath();
@@ -349,8 +247,7 @@ bool Params::parseParams(const QStringList &paramsArray, const OptionsDataList &
349247
}
350248

351249
void Params::printWorkingOptions() {
352-
QuasarAppUtils::Params::log("--- Working options table start ---",
353-
QuasarAppUtils::Debug);
250+
qDebug() << "--- Working options table start ---";
354251

355252
QMap<QString, QString>::const_iterator iter = params.constBegin();
356253
while (iter != params.constEnd()) {
@@ -362,23 +259,24 @@ void Params::printWorkingOptions() {
362259
row += QString{": %1"}.arg(value);
363260
}
364261

365-
QuasarAppUtils::Params::log(row, QuasarAppUtils::Debug);
262+
qDebug() << row;
366263

367264
++iter;
368265
}
369266

370-
QuasarAppUtils::Params::log("--- Working options table end ---",
371-
QuasarAppUtils::Debug);
267+
qDebug() << "--- Working options table end ---";
372268
}
373269

374270
bool Params::checkOption(const OptionData& optionData, const QString& rawOptionName) {
375271

376272
#ifndef QA_ALLOW_NOT_SUPPORTED_OPTIONS
377273
if (!optionData.isValid()) {
378-
QuasarAppUtils::Params::log(QString("The '%0' option not exists!"
379-
" You use wrong option name, please check the help before run your commnad.").arg(
380-
rawOptionName),
381-
QuasarAppUtils::Error);
274+
275+
qCritical() << QString("The '%0' option not exists!"
276+
" You use wrong option name,"
277+
" please check the help before run your commnad.").
278+
arg(rawOptionName);
279+
382280
return false;
383281
}
384282
#else
@@ -390,19 +288,17 @@ bool Params::checkOption(const OptionData& optionData, const QString& rawOptionN
390288

391289

392290
if (optionData.isRemoved()) {
393-
QuasarAppUtils::Params::log(optionData.depricatedMsg(),
394-
QuasarAppUtils::Error);
291+
qCritical() << optionData.depricatedMsg();
292+
395293
return false;
396294
}
397295

398-
QuasarAppUtils::Params::log(QString("The %0 option(s) marked as deprecated! "
399-
"And most likely will be removed in next release.").
400-
arg(optionData.names().join("/")),
401-
QuasarAppUtils::Warning);
296+
qWarning() << QString("The %0 option(s) marked as deprecated! "
297+
"And most likely will be removed in next release.").
298+
arg(optionData.names().join("/"));
402299

300+
qWarning() << QString("Option message: %0").arg(optionData.depricatedMsg());
403301

404-
QuasarAppUtils::Params::log(QString("Option message: %0").arg(optionData.depricatedMsg()),
405-
QuasarAppUtils::Warning);
406302
}
407303

408304
return true;

params.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class QUASARAPPSHARED_EXPORT Params
131131
* @note All messages will be printed according to the current verbose setting.
132132
* @note The verbose level sets by verbose option on console.
133133
*/
134+
[[deprecated("Use QALogger and qt debug functions(qDebug, qInfo, qError...)")]]
134135
static void log(const QString& log, VerboseLvl vLvl = VerboseLvl::Debug);
135136

136137
/**
@@ -149,6 +150,7 @@ class QUASARAPPSHARED_EXPORT Params
149150
* @brief isDebugBuild This method return true if the library buildet in debug mode.
150151
* @return true if this library buildet in debug mode.
151152
*/
153+
[[deprecated("Use Qt MACROSSSES")]]
152154
static bool isDebugBuild();
153155

154156
/**
@@ -217,10 +219,6 @@ class QUASARAPPSHARED_EXPORT Params
217219
static OptionsDataList availableArguments();
218220

219221
private:
220-
static QString timeString();
221-
static QString lvlToString(VerboseLvl vLvl);
222-
static bool writeLoginFile(const QString& log, VerboseLvl vLvl = VerboseLvl::Debug);
223-
224222

225223
static bool optionsForEach(const QStringList& paramsArray,
226224
const OptionsDataList &availableOptions);

qaglobalutils.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
#ifndef QU_GLOBAL_UTILS_H
99
#define QU_GLOBAL_UTILS_H
1010

11-
#include <cstdlib>
1211
#include <type_traits>
13-
#include <string>
1412
#include <typeinfo>
1513
#include <QByteArray>
1614
#include "QtGlobal"
17-
#include "params.h"
18-
15+
#include "quasarapp_global.h"
1916

2017
template <typename T>
2118
constexpr inline T operator | (T lhs, T rhs)
@@ -150,18 +147,7 @@ uint8_t static_type_hash_8(T& object) noexcept {
150147
#define H_32 static_type_hash_32
151148

152149

153-
#ifndef QT_DEBUG
154-
// The debug_assert it is assert that abort application only in debug mode.
155-
// In the release mode This assert prin Error message only.
156-
#define debug_assert(condition, msg) \
157-
if (!condition) \
158-
QuasarAppUtils::Params::log(msg, QuasarAppUtils::Error);
159-
160-
#else
161-
// The debug_assert it is assert that abort application only in debug mode.
162-
// In the release mode This assert prin Error message only.
163-
#define debug_assert(condition, msg) assert(condition && msg)
164-
#endif
150+
#define debug_assert(C, M) Q_ASSERT(C && M)
165151

166152
/**
167153
* @brief randomArray This function return random arrat with size @a size

0 commit comments

Comments
 (0)