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
2422using namespace QuasarAppUtils ;
@@ -35,66 +33,27 @@ bool Params::isEndable(const QString& key) {
3533
3634void 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-
253153bool Params::optionsForEach (const QStringList ¶msArray,
254154 const OptionsDataList& availableOptions) {
255155
@@ -274,8 +174,7 @@ bool Params::optionsForEach(const QStringList ¶msArray,
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 ¶msArray, 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 ¶msArray, const OptionsDataList &
349247}
350248
351249void 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
374270bool 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 ;
0 commit comments