mirror of
https://github.com/QuasarApp/QuasarAppLib.git
synced 2025-04-26 09:44:38 +00:00
ixes of the loger and settings classes
This commit is contained in:
parent
9c6c6d257c
commit
7e84073393
30
qalogger.cpp
30
qalogger.cpp
@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
namespace QuasarAppUtils {
|
namespace QuasarAppUtils {
|
||||||
|
|
||||||
static QFile* _logFile;
|
Q_GLOBAL_STATIC(QString, _logFile)
|
||||||
|
|
||||||
static bool _toFile = false;
|
static bool _toFile = false;
|
||||||
static VerboseLvl _verboseLevel = Debug;
|
static VerboseLvl _verboseLevel = Debug;
|
||||||
|
|
||||||
@ -28,12 +29,9 @@ static VerboseLvl _verboseLevel = Debug;
|
|||||||
|
|
||||||
|
|
||||||
QALogger::QALogger() {
|
QALogger::QALogger() {
|
||||||
_logFile = new QFile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QALogger::~QALogger() {
|
QALogger::~QALogger() {
|
||||||
_logFile->close();
|
|
||||||
delete _logFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -55,18 +53,17 @@ void messageHandler(QtMsgType type, const QMessageLogContext & context, const QS
|
|||||||
|
|
||||||
|
|
||||||
if (checkLogType(type, _verboseLevel)) {
|
if (checkLogType(type, _verboseLevel)) {
|
||||||
if (_toFile && _logFile) {
|
if (_toFile && _logFile->size()) {
|
||||||
QTextStream stream(_logFile);
|
QFile logFile(*_logFile);
|
||||||
|
if (logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
||||||
|
QTextStream stream(&logFile);
|
||||||
stream << qFormatLogMessage(type, context, msg) << Qt::endl;
|
stream << qFormatLogMessage(type, context, msg) << Qt::endl;
|
||||||
_logFile->flush();
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QtMsgType::QtFatalMsg: {
|
case QtMsgType::QtFatalMsg:
|
||||||
Q_ASSERT_X(false, __FUNCTION__ , qFormatLogMessage(type, context, msg).toLatin1().data());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case QtMsgType::QtCriticalMsg:
|
case QtMsgType::QtCriticalMsg:
|
||||||
case QtMsgType::QtWarningMsg: {
|
case QtMsgType::QtWarningMsg: {
|
||||||
std::cerr << qFormatLogMessage(type, context, msg).toStdString() << std::endl;
|
std::cerr << qFormatLogMessage(type, context, msg).toStdString() << std::endl;
|
||||||
@ -95,7 +92,8 @@ void QALogger::init() {
|
|||||||
if (Params::isEndable("fileLog")) {
|
if (Params::isEndable("fileLog")) {
|
||||||
_toFile = true;
|
_toFile = true;
|
||||||
QString path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
|
QString path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
|
||||||
QString filePath = path + "/" + QCoreApplication::applicationName() + ".log";
|
QString filePath = path + "/" + QCoreApplication::applicationName() +
|
||||||
|
" " + QDate::currentDate().toString(Qt::DateFormat::ISODate) + ".log";
|
||||||
auto file = Params::getArg("fileLog");
|
auto file = Params::getArg("fileLog");
|
||||||
if (file.size()) {
|
if (file.size()) {
|
||||||
filePath = file;
|
filePath = file;
|
||||||
@ -103,11 +101,7 @@ void QALogger::init() {
|
|||||||
|
|
||||||
QDir().mkpath(path);
|
QDir().mkpath(path);
|
||||||
|
|
||||||
_logFile->setFileName(filePath);
|
*_logFile = filePath;
|
||||||
|
|
||||||
if (!_logFile->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
|
||||||
qFatal() << "Can't open log file";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,4 +69,13 @@ bool Settings::initService() {
|
|||||||
return ISettings::initService(std::make_unique<Settings>());
|
return ISettings::initService(std::make_unique<Settings>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ISettings *Settings::autoInstance() {
|
||||||
|
if (auto result = instance()) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings::initService();
|
||||||
|
return ISettings::instance();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
static bool initService();
|
static bool initService();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief deinitService This method destroy default object of the QuasarAppUtils::Settings type.
|
||||||
|
* @see ISettings::deinitService
|
||||||
|
*/
|
||||||
|
static ISettings *autoInstance();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void syncImplementation() override;
|
void syncImplementation() override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user