2017-11-11 17:44:05 -05:00
|
|
|
/*
|
|
|
|
* loggerwithfile.cpp
|
|
|
|
*
|
|
|
|
* Created on: Nov 11, 2017
|
|
|
|
* Author: f4exb
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "loggerwithfile.h"
|
|
|
|
|
|
|
|
using namespace qtwebapp;
|
|
|
|
|
|
|
|
LoggerWithFile::LoggerWithFile(QObject* parent)
|
|
|
|
:Logger(parent), fileLogger(0), useFileFlogger(false)
|
|
|
|
{
|
|
|
|
consoleLogger = new Logger(this);
|
|
|
|
}
|
|
|
|
|
2017-11-11 20:23:55 -05:00
|
|
|
LoggerWithFile::~LoggerWithFile()
|
2017-11-11 17:44:05 -05:00
|
|
|
{
|
2017-11-11 20:23:55 -05:00
|
|
|
destroyFileLogger();
|
|
|
|
delete consoleLogger;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoggerWithFile::createOrSetFileLogger(const FileLoggerSettings& settings, const int refreshInterval)
|
|
|
|
{
|
|
|
|
if (!fileLogger) {
|
|
|
|
fileLogger = new FileLogger(settings, refreshInterval, this);
|
|
|
|
} else {
|
|
|
|
fileLogger->setFileLoggerSettings(settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoggerWithFile::destroyFileLogger()
|
|
|
|
{
|
|
|
|
if (fileLogger)
|
|
|
|
{
|
|
|
|
delete fileLogger;
|
|
|
|
fileLogger = 0;
|
|
|
|
}
|
2017-11-11 17:44:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoggerWithFile::log(const QtMsgType type, const QString& message, const QString &file, const QString &function, const int line)
|
|
|
|
{
|
|
|
|
consoleLogger->log(type,message,file,function,line);
|
|
|
|
|
|
|
|
if (fileLogger && useFileFlogger) {
|
|
|
|
fileLogger->log(type,message,file,function,line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-06 20:52:35 -05:00
|
|
|
void LoggerWithFile::logToFile(const QtMsgType type, const QString& message, const QString &file, const QString &function, const int line)
|
|
|
|
{
|
|
|
|
if (fileLogger && useFileFlogger) {
|
|
|
|
fileLogger->log(type,message,file,function,line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 17:44:05 -05:00
|
|
|
void LoggerWithFile::clear(const bool buffer, const bool variables)
|
|
|
|
{
|
|
|
|
consoleLogger->clear(buffer,variables);
|
|
|
|
|
|
|
|
if (fileLogger && useFileFlogger) {
|
|
|
|
fileLogger->clear(buffer,variables);
|
|
|
|
}
|
|
|
|
}
|
2017-11-11 18:01:47 -05:00
|
|
|
|
2017-11-11 20:23:55 -05:00
|
|
|
void LoggerWithFile::setConsoleMinMessageLevel(const QtMsgType& msgLevel)
|
2017-11-11 18:01:47 -05:00
|
|
|
{
|
|
|
|
consoleLogger->setMinMessageLevel(msgLevel);
|
2017-11-11 20:23:55 -05:00
|
|
|
}
|
2017-11-11 18:01:47 -05:00
|
|
|
|
2017-11-11 20:23:55 -05:00
|
|
|
void LoggerWithFile::setFileMinMessageLevel(const QtMsgType& msgLevel)
|
|
|
|
{
|
2017-11-11 18:01:47 -05:00
|
|
|
if (fileLogger) {
|
|
|
|
fileLogger->setMinMessageLevel(msgLevel);
|
|
|
|
}
|
|
|
|
}
|
2017-11-18 14:07:53 -05:00
|
|
|
|
|
|
|
void LoggerWithFile::getConsoleMinMessageLevelStr(QString& levelStr)
|
|
|
|
{
|
|
|
|
switch (consoleLogger->getMinMessageLevel())
|
|
|
|
{
|
|
|
|
case QtDebugMsg:
|
|
|
|
levelStr = "debug";
|
|
|
|
break;
|
|
|
|
case QtInfoMsg:
|
|
|
|
levelStr = "info";
|
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
|
|
|
levelStr = "warning";
|
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
|
|
|
case QtFatalMsg:
|
|
|
|
levelStr = "error";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
levelStr = "debug";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoggerWithFile::getFileMinMessageLevelStr(QString& levelStr)
|
|
|
|
{
|
|
|
|
switch (fileLogger->getMinMessageLevel())
|
|
|
|
{
|
|
|
|
case QtDebugMsg:
|
|
|
|
levelStr = "debug";
|
|
|
|
break;
|
|
|
|
case QtInfoMsg:
|
|
|
|
levelStr = "info";
|
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
|
|
|
levelStr = "warning";
|
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
|
|
|
case QtFatalMsg:
|
|
|
|
levelStr = "error";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
levelStr = "debug";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoggerWithFile::getLogFileName(QString& fileName)
|
|
|
|
{
|
|
|
|
fileName = fileLogger->getFileLoggerSettings().fileName;
|
|
|
|
}
|