added new option for desable logs

This commit is contained in:
Andrei Yankovich 2023-11-05 11:24:09 +01:00
parent 334e209ff4
commit 3b797f9a78
3 changed files with 25 additions and 15 deletions

View File

@ -41,11 +41,16 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
option(QA_ASSERT_ON_WARN "Enable for add assert to every warning message" OFF)
option(QA_ASSERT_ON_ERROR "Enable for add assert to every error message" OFF)
option(QA_ALLOW_NOT_SUPPORTED_OPTIONS "Enable for allow any command line options" ON)
option(QA_DISABLE_LOG "Disabled all logs (force sets verbose to 0)" OFF)
if (QA_ASSERT_ON_WARN)
add_definitions(-DQA_ASSERT_ON_WARN)
endif()
if (QA_DISABLE_LOG)
add_definitions(-DQA_DISABLE_LOG)
endif()
if (QA_ASSERT_ON_ERROR)
add_definitions(-DQA_ASSERT_ON_ERROR)
endif()

View File

@ -222,27 +222,29 @@ QString Params::lvlToString(VerboseLvl vLvl) {
bool Params::writeLoginFile(const QString &log, VerboseLvl vLvl) {
if (isEndable("fileLog")) {
QString path = getCurrentExecutable() + ".log";
auto file = getArg("fileLog");
if (file.size()) {
path = file;
}
auto lvl = getVerboseLvl();
if (vLvl <= lvl) {
QString path = getCurrentExecutable() + ".log";
auto file = getArg("fileLog");
if (file.size()) {
path = file;
}
QFile logFile(path);
QFile logFile(path);
if (logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
if (logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
QTextStream stream(&logFile);
QTextStream stream(&logFile);
#if QT_VERSION > QT_VERSION_CHECK(5, 14, 0)
stream << timeString() <<"| " << lvlToString(vLvl) + ": " + log << Qt::endl;
stream << timeString() <<"| " << lvlToString(vLvl) + ": " + log << Qt::endl;
#else
stream << timeString() <<"| " << lvlToString(vLvl) + ": " + log << endl;
stream << timeString() <<"| " << lvlToString(vLvl) + ": " + log << endl;
#endif
logFile.close();
} else {
return false;
logFile.close();
} else {
return false;
}
}
}
return true;

View File

@ -31,12 +31,15 @@ enum VerboseLvl {
Debug = 0x3,
};
#ifdef QA_DISABLE_LOG
#define DEFAULT_VERBOSE_LVL "0"
#else
#ifdef QT_DEBUG
#define DEFAULT_VERBOSE_LVL "3"
#else
#define DEFAULT_VERBOSE_LVL "2"
#endif
#endif
/**
* @brief The Params class Contains fonctions for working with input arguments and logs.