mirror of
https://github.com/QuasarApp/QuasarAppLib.git
synced 2025-05-01 04:04:42 +00:00
Merge pull request #43 from QuasarApp/qt_logger
move to qt logger system
This commit is contained in:
commit
a21c8d38ed
@ -63,12 +63,11 @@ file(GLOB SOURCE_CPP
|
|||||||
"*.cpp" "*.h"
|
"*.cpp" "*.h"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} ${SOURCE_CPP}
|
add_library(${PROJECT_NAME} ${SOURCE_CPP})
|
||||||
qasecretservice.h qasecretservice.cpp)
|
|
||||||
target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Core)
|
target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Core)
|
||||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
setVersion(1 5 3)
|
setVersion(1 5 4)
|
||||||
|
|
||||||
initAll()
|
initAll()
|
||||||
make_directory("${CMAKE_CURRENT_SOURCE_DIR}/Distro")
|
make_directory("${CMAKE_CURRENT_SOURCE_DIR}/Distro")
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
17
locales.cpp
17
locales.cpp
@ -15,7 +15,6 @@
|
|||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include "params.h"
|
|
||||||
|
|
||||||
using namespace QuasarAppUtils;
|
using namespace QuasarAppUtils;
|
||||||
|
|
||||||
@ -31,17 +30,15 @@ bool QuasarAppUtils::Locales::findQmPrivate(const QString &prefix,
|
|||||||
auto qmFile = new QTranslator();
|
auto qmFile = new QTranslator();
|
||||||
|
|
||||||
if(!qmFile->load(file.absoluteFilePath())) {
|
if(!qmFile->load(file.absoluteFilePath())) {
|
||||||
QuasarAppUtils::Params::log("Failed to load translation file : "
|
qWarning() << "Failed to load translation file : "
|
||||||
+ file.absoluteFilePath(),
|
+ file.absoluteFilePath();
|
||||||
QuasarAppUtils::Warning);
|
|
||||||
delete qmFile;
|
delete qmFile;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qmFile->isEmpty()) {
|
if (qmFile->isEmpty()) {
|
||||||
QuasarAppUtils::Params::log("Translation file is Empty: " +
|
qDebug() << "Translation file is Empty: " +
|
||||||
file.absoluteFilePath(),
|
file.absoluteFilePath();
|
||||||
QuasarAppUtils::Debug);
|
|
||||||
delete qmFile;
|
delete qmFile;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -51,7 +48,7 @@ bool QuasarAppUtils::Locales::findQmPrivate(const QString &prefix,
|
|||||||
auto message = QString("The target language (%0) and a choosed qm file (%1) "
|
auto message = QString("The target language (%0) and a choosed qm file (%1) "
|
||||||
"is different, Loading will be skiped: ").
|
"is different, Loading will be skiped: ").
|
||||||
arg(language, file.absoluteFilePath());
|
arg(language, file.absoluteFilePath());
|
||||||
QuasarAppUtils::Params::log(message, QuasarAppUtils::Debug);
|
qDebug() << message;
|
||||||
|
|
||||||
delete qmFile;
|
delete qmFile;
|
||||||
continue;
|
continue;
|
||||||
@ -85,9 +82,7 @@ void QuasarAppUtils::Locales::installTranslations( QList<QTranslator *> &qmFiles
|
|||||||
for (const auto & translator: std::as_const(qmFiles)) {
|
for (const auto & translator: std::as_const(qmFiles)) {
|
||||||
if (!QCoreApplication::installTranslator(translator)) {
|
if (!QCoreApplication::installTranslator(translator)) {
|
||||||
|
|
||||||
QuasarAppUtils::Params::log("Failed to install translation file : " + translator->filePath(),
|
qWarning() << "Failed to install translation file : " + translator->filePath();
|
||||||
QuasarAppUtils::Warning);
|
|
||||||
|
|
||||||
delete translator;
|
delete translator;
|
||||||
// we use a link of qmFiles so remove all invalid translations.
|
// we use a link of qmFiles so remove all invalid translations.
|
||||||
qmFiles.removeAll(translator);
|
qmFiles.removeAll(translator);
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "optiondata.h"
|
#include "optiondata.h"
|
||||||
#include "qaglobalutils.h"
|
|
||||||
|
|
||||||
namespace QuasarAppUtils{
|
namespace QuasarAppUtils{
|
||||||
|
|
||||||
|
148
params.cpp
148
params.cpp
@ -9,16 +9,14 @@
|
|||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <iostream>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include "qaglobalutils.h"
|
#include <QtLogging>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace QuasarAppUtils;
|
using namespace QuasarAppUtils;
|
||||||
@ -35,66 +33,27 @@ bool Params::isEndable(const QString& key) {
|
|||||||
|
|
||||||
void Params::log(const QString &log, VerboseLvl vLvl) {
|
void Params::log(const QString &log, VerboseLvl vLvl) {
|
||||||
|
|
||||||
writeLoginFile(log, vLvl);
|
|
||||||
|
|
||||||
auto lvl = getVerboseLvl();
|
auto lvl = getVerboseLvl();
|
||||||
if (vLvl <= lvl) {
|
if (vLvl <= lvl) {
|
||||||
|
|
||||||
switch (vLvl) {
|
switch (vLvl) {
|
||||||
|
|
||||||
case VerboseLvl::Error:
|
case VerboseLvl::Error:
|
||||||
#ifdef Q_OS_WIN32
|
qCritical().noquote() << log;
|
||||||
std::cerr << QString{lvlToString(vLvl) + ": " + log}.toStdString() << std::endl;
|
|
||||||
#else
|
|
||||||
qCritical().noquote() << lvlToString(vLvl) + ": " + log;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef QA_ASSERT_ON_ERROR
|
|
||||||
#ifdef __GNUC__
|
|
||||||
__builtin_trap();
|
|
||||||
#else
|
|
||||||
debug_assert(false, "You requested to throw assert in every error message."
|
|
||||||
" See The ASSERT_ON_ERROR option in cmake config.");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VerboseLvl::Warning: {
|
case VerboseLvl::Warning: {
|
||||||
#ifdef Q_OS_WIN32
|
qWarning().noquote() << log;
|
||||||
std::cerr << QString{lvlToString(vLvl) + ": " + log}.toStdString() << std::endl;
|
|
||||||
#else
|
|
||||||
qWarning().noquote() << lvlToString(vLvl) + ": " + log;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef QA_ASSERT_ON_WARN
|
|
||||||
#ifdef __GNUC__
|
|
||||||
__builtin_trap();
|
|
||||||
#else
|
|
||||||
debug_assert(false, "You requested to throw assert in every warning message."
|
|
||||||
" See The ASSERT_ON_ERROR option in cmake config.");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case VerboseLvl::Debug: {
|
case VerboseLvl::Debug: {
|
||||||
#ifdef Q_OS_WIN32
|
qDebug().noquote() << log;
|
||||||
std::cout << QString{lvlToString(vLvl) + ": " + log}.toStdString() << std::endl;
|
|
||||||
#else
|
|
||||||
qDebug().noquote() << lvlToString(vLvl) + ": " + log;
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case VerboseLvl::Info:
|
case VerboseLvl::Info:
|
||||||
default: {
|
default: {
|
||||||
#ifdef Q_OS_WIN32
|
qInfo().noquote() << log;
|
||||||
std::cout << QString{lvlToString(vLvl) + ": " + log}.toStdString() << std::endl;
|
|
||||||
#else
|
|
||||||
qInfo().noquote() << lvlToString(vLvl) + ": " + log;
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,65 +150,6 @@ int Params::size() {
|
|||||||
return params.size();
|
return params.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Params::timeString() {
|
|
||||||
return QDateTime::currentDateTime().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Params::lvlToString(VerboseLvl vLvl) {
|
|
||||||
switch (vLvl) {
|
|
||||||
|
|
||||||
case VerboseLvl::Error: {
|
|
||||||
return "Error";
|
|
||||||
}
|
|
||||||
|
|
||||||
case VerboseLvl::Warning: {
|
|
||||||
return "Warning";
|
|
||||||
}
|
|
||||||
|
|
||||||
case VerboseLvl::Info: {
|
|
||||||
return "Info";
|
|
||||||
}
|
|
||||||
|
|
||||||
case VerboseLvl::Debug: {
|
|
||||||
return "Verbose log";
|
|
||||||
}
|
|
||||||
default: return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Params::writeLoginFile(const QString &log, VerboseLvl vLvl) {
|
|
||||||
if (isEndable("fileLog")) {
|
|
||||||
|
|
||||||
auto lvl = getVerboseLvl();
|
|
||||||
if (vLvl <= lvl) {
|
|
||||||
QString path = getCurrentExecutable() + ".log";
|
|
||||||
auto file = getArg("fileLog");
|
|
||||||
if (file.size()) {
|
|
||||||
path = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile logFile(path);
|
|
||||||
|
|
||||||
if (logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
|
||||||
|
|
||||||
QTextStream stream(&logFile);
|
|
||||||
#if QT_VERSION > QT_VERSION_CHECK(5, 14, 0)
|
|
||||||
stream << timeString() <<"| " << lvlToString(vLvl) + ": " + log << Qt::endl;
|
|
||||||
#else
|
|
||||||
stream << timeString() <<"| " << lvlToString(vLvl) + ": " + log << endl;
|
|
||||||
#endif
|
|
||||||
logFile.close();
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Params::optionsForEach(const QStringList ¶msArray,
|
bool Params::optionsForEach(const QStringList ¶msArray,
|
||||||
const OptionsDataList& availableOptions) {
|
const OptionsDataList& availableOptions) {
|
||||||
|
|
||||||
@ -274,8 +174,7 @@ bool Params::optionsForEach(const QStringList ¶msArray,
|
|||||||
params[paramsArray[i].mid(1)] = paramsArray[i + 1];
|
params[paramsArray[i].mid(1)] = paramsArray[i + 1];
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
QuasarAppUtils::Params::log("Missing argument for " + paramsArray[i],
|
qCritical() << "Missing argument for " + paramsArray[i];
|
||||||
QuasarAppUtils::Error);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -322,8 +221,7 @@ bool Params::parseParams(const QStringList ¶msArray, const OptionsDataList &
|
|||||||
memset(path, 0, sizeof path);
|
memset(path, 0, sizeof path);
|
||||||
|
|
||||||
if (readlink("/proc/self/exe", path, 2048) < 0) {
|
if (readlink("/proc/self/exe", path, 2048) < 0) {
|
||||||
QuasarAppUtils::Params::log("parseParams can't get self path!",
|
qCritical() << "parseParams can't get self path!";
|
||||||
QuasarAppUtils::Error);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
appPath = QFileInfo(path).absolutePath();
|
appPath = QFileInfo(path).absolutePath();
|
||||||
@ -349,8 +247,7 @@ bool Params::parseParams(const QStringList ¶msArray, const OptionsDataList &
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Params::printWorkingOptions() {
|
void Params::printWorkingOptions() {
|
||||||
QuasarAppUtils::Params::log("--- Working options table start ---",
|
qDebug() << "--- Working options table start ---";
|
||||||
QuasarAppUtils::Debug);
|
|
||||||
|
|
||||||
QMap<QString, QString>::const_iterator iter = params.constBegin();
|
QMap<QString, QString>::const_iterator iter = params.constBegin();
|
||||||
while (iter != params.constEnd()) {
|
while (iter != params.constEnd()) {
|
||||||
@ -362,23 +259,24 @@ void Params::printWorkingOptions() {
|
|||||||
row += QString{": %1"}.arg(value);
|
row += QString{": %1"}.arg(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
QuasarAppUtils::Params::log(row, QuasarAppUtils::Debug);
|
qDebug() << row;
|
||||||
|
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
QuasarAppUtils::Params::log("--- Working options table end ---",
|
qDebug() << "--- Working options table end ---";
|
||||||
QuasarAppUtils::Debug);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Params::checkOption(const OptionData& optionData, const QString& rawOptionName) {
|
bool Params::checkOption(const OptionData& optionData, const QString& rawOptionName) {
|
||||||
|
|
||||||
#ifndef QA_ALLOW_NOT_SUPPORTED_OPTIONS
|
#ifndef QA_ALLOW_NOT_SUPPORTED_OPTIONS
|
||||||
if (!optionData.isValid()) {
|
if (!optionData.isValid()) {
|
||||||
QuasarAppUtils::Params::log(QString("The '%0' option not exists!"
|
|
||||||
" You use wrong option name, please check the help before run your commnad.").arg(
|
qCritical() << QString("The '%0' option not exists!"
|
||||||
rawOptionName),
|
" You use wrong option name,"
|
||||||
QuasarAppUtils::Error);
|
" please check the help before run your commnad.").
|
||||||
|
arg(rawOptionName);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -390,19 +288,17 @@ bool Params::checkOption(const OptionData& optionData, const QString& rawOptionN
|
|||||||
|
|
||||||
|
|
||||||
if (optionData.isRemoved()) {
|
if (optionData.isRemoved()) {
|
||||||
QuasarAppUtils::Params::log(optionData.depricatedMsg(),
|
qCritical() << optionData.depricatedMsg();
|
||||||
QuasarAppUtils::Error);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QuasarAppUtils::Params::log(QString("The %0 option(s) marked as deprecated! "
|
qWarning() << QString("The %0 option(s) marked as deprecated! "
|
||||||
"And most likely will be removed in next release.").
|
"And most likely will be removed in next release.").
|
||||||
arg(optionData.names().join("/")),
|
arg(optionData.names().join("/"));
|
||||||
QuasarAppUtils::Warning);
|
|
||||||
|
|
||||||
|
qWarning() << QString("Option message: %0").arg(optionData.depricatedMsg());
|
||||||
|
|
||||||
QuasarAppUtils::Params::log(QString("Option message: %0").arg(optionData.depricatedMsg()),
|
|
||||||
QuasarAppUtils::Warning);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
6
params.h
6
params.h
@ -131,6 +131,7 @@ public:
|
|||||||
* @note All messages will be printed according to the current verbose setting.
|
* @note All messages will be printed according to the current verbose setting.
|
||||||
* @note The verbose level sets by verbose option on console.
|
* @note The verbose level sets by verbose option on console.
|
||||||
*/
|
*/
|
||||||
|
[[deprecated("Use QALogger and qt debug functions(qDebug, qInfo, qError...)")]]
|
||||||
static void log(const QString& log, VerboseLvl vLvl = VerboseLvl::Debug);
|
static void log(const QString& log, VerboseLvl vLvl = VerboseLvl::Debug);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,6 +150,7 @@ public:
|
|||||||
* @brief isDebugBuild This method return true if the library buildet in debug mode.
|
* @brief isDebugBuild This method return true if the library buildet in debug mode.
|
||||||
* @return true if this library buildet in debug mode.
|
* @return true if this library buildet in debug mode.
|
||||||
*/
|
*/
|
||||||
|
[[deprecated("Use Qt MACROSSSES")]]
|
||||||
static bool isDebugBuild();
|
static bool isDebugBuild();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -217,10 +219,6 @@ public:
|
|||||||
static OptionsDataList availableArguments();
|
static OptionsDataList availableArguments();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QString timeString();
|
|
||||||
static QString lvlToString(VerboseLvl vLvl);
|
|
||||||
static bool writeLoginFile(const QString& log, VerboseLvl vLvl = VerboseLvl::Debug);
|
|
||||||
|
|
||||||
|
|
||||||
static bool optionsForEach(const QStringList& paramsArray,
|
static bool optionsForEach(const QStringList& paramsArray,
|
||||||
const OptionsDataList &availableOptions);
|
const OptionsDataList &availableOptions);
|
||||||
|
@ -8,14 +8,11 @@
|
|||||||
#ifndef QU_GLOBAL_UTILS_H
|
#ifndef QU_GLOBAL_UTILS_H
|
||||||
#define QU_GLOBAL_UTILS_H
|
#define QU_GLOBAL_UTILS_H
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <string>
|
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include "QtGlobal"
|
#include "QtGlobal"
|
||||||
#include "params.h"
|
#include "quasarapp_global.h"
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr inline T operator | (T lhs, T rhs)
|
constexpr inline T operator | (T lhs, T rhs)
|
||||||
@ -150,18 +147,7 @@ uint8_t static_type_hash_8(T& object) noexcept {
|
|||||||
#define H_32 static_type_hash_32
|
#define H_32 static_type_hash_32
|
||||||
|
|
||||||
|
|
||||||
#ifndef QT_DEBUG
|
#define debug_assert(C, M) Q_ASSERT(C && M)
|
||||||
// The debug_assert it is assert that abort application only in debug mode.
|
|
||||||
// In the release mode This assert prin Error message only.
|
|
||||||
#define debug_assert(condition, msg) \
|
|
||||||
if (!condition) \
|
|
||||||
QuasarAppUtils::Params::log(msg, QuasarAppUtils::Error);
|
|
||||||
|
|
||||||
#else
|
|
||||||
// The debug_assert it is assert that abort application only in debug mode.
|
|
||||||
// In the release mode This assert prin Error message only.
|
|
||||||
#define debug_assert(condition, msg) assert(condition && msg)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief randomArray This function return random arrat with size @a size
|
* @brief randomArray This function return random arrat with size @a size
|
||||||
|
67
qalogger.cpp
Normal file
67
qalogger.cpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024-2024 QuasarApp.
|
||||||
|
* Distributed under the lgplv3 software license, see the accompanying
|
||||||
|
* Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
* of this license document, but changing it is not allowed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "qalogger.h"
|
||||||
|
#include "params.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
|
namespace QuasarAppUtils {
|
||||||
|
|
||||||
|
|
||||||
|
#define MESSAGE_PATTERN \
|
||||||
|
"[%{time MM-dd h:mm:ss.zzz} %{threadid} " \
|
||||||
|
"%{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] " \
|
||||||
|
"%{message}"
|
||||||
|
|
||||||
|
|
||||||
|
bool checkLogType(QtMsgType type, VerboseLvl lvl) {
|
||||||
|
switch (type) {
|
||||||
|
case QtDebugMsg: return lvl >= Debug;
|
||||||
|
case QtInfoMsg: return lvl >= Info;
|
||||||
|
case QtWarningMsg: return lvl >= Warning;
|
||||||
|
|
||||||
|
case QtCriticalMsg:
|
||||||
|
case QtFatalMsg:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
void messageHandler(QtMsgType type, const QMessageLogContext &, const QString &msg) {
|
||||||
|
|
||||||
|
if (Params::isEndable("fileLog")) {
|
||||||
|
auto verboselvl = Params::getVerboseLvl();
|
||||||
|
if (checkLogType(type, verboselvl)) {
|
||||||
|
QString path = Params::getCurrentExecutable() + ".log";
|
||||||
|
auto file = Params::getArg("fileLog");
|
||||||
|
if (file.size()) {
|
||||||
|
path = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile logFile(path);
|
||||||
|
if (logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
||||||
|
|
||||||
|
QTextStream stream(&logFile);
|
||||||
|
#if QT_VERSION > QT_VERSION_CHECK(5, 14, 0)
|
||||||
|
stream << msg << Qt::endl;
|
||||||
|
#else
|
||||||
|
stream << msg << endl;
|
||||||
|
#endif
|
||||||
|
logFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QALogger::init() {
|
||||||
|
qSetMessagePattern(MESSAGE_PATTERN);
|
||||||
|
qInstallMessageHandler(messageHandler);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
33
qalogger.h
Normal file
33
qalogger.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024-2024 QuasarApp.
|
||||||
|
* Distributed under the lgplv3 software license, see the accompanying
|
||||||
|
* Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
* of this license document, but changing it is not allowed.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef QALOGGER_H
|
||||||
|
#define QALOGGER_H
|
||||||
|
|
||||||
|
#include "quasarapp_global.h"
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
namespace QuasarAppUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The QALogger class is logger handler for app.
|
||||||
|
*/
|
||||||
|
class QUASARAPPSHARED_EXPORT QALogger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QALogger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief init This method initialize logging of all qt message into file.
|
||||||
|
*/
|
||||||
|
void init();
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // QALOGGER_H
|
@ -5,4 +5,3 @@
|
|||||||
* of this license document, but changing it is not allowed.
|
* of this license document, but changing it is not allowed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qaservice.h"
|
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
* of this license document, but changing it is not allowed.
|
* of this license document, but changing it is not allowed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "quasarapp.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user