diff options
Diffstat (limited to 'Logger')
| -rw-r--r-- | Logger/cyclelogfile.cpp | 48 | ||||
| -rw-r--r-- | Logger/initlog.cpp | 37 | ||||
| -rw-r--r-- | Logger/logevent.cpp | 20 | ||||
| -rw-r--r-- | Logger/logger.cpp | 10 | ||||
| -rw-r--r-- | Logger/logger.h | 46 | ||||
| -rw-r--r-- | Logger/logprimitive.h | 12 | ||||
| -rw-r--r-- | Logger/openlogfile.cpp | 21 | ||||
| -rw-r--r-- | Logger/writelogfile.cpp | 18 |
8 files changed, 0 insertions, 212 deletions
diff --git a/Logger/cyclelogfile.cpp b/Logger/cyclelogfile.cpp deleted file mode 100644 index cb0266e..0000000 --- a/Logger/cyclelogfile.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "logger.h" - -// if "now" matches the previous logfile name, no cycling needed. otherwise, determine new logfile name. -bool Logger::cycleLogFile() -{ - // calculate the expected log filename - QString newFilename = _logLabel; - - // get date to see if we need to cycle - QDate date(QDate::currentDate()); - - // when is it necessary to cycle? - switch ( _cyclePeriod ) - { - case 1: // yearly - newFilename += date.toString("-yyyy"); - break; - case 2: // monthly - newFilename += date.toString("-yyyy-MM"); - break; - case 3: // weekly - newFilename += date.toString("-yyyy") + "-week" + QString("%1").arg(date.weekNumber(), 2, 10, QChar('0')); - break; - case 4: // daily - newFilename += date.toString("-yyyy-MM-dd"); - break; - default:; // 0 = never - } - - // add log file extension - newFilename += ".log"; - - // if current and new filename are not the same, cycle log file - if (_logFileName != newFilename) - { - // cycle log file - _logFileName = newFilename; - - // close the existing/opened log file - closeLogFile(); - - // open the new log file (pass possible error to caller) - return openLogFile(); - } - - // else: no cycling necessary - return true; -} diff --git a/Logger/initlog.cpp b/Logger/initlog.cpp deleted file mode 100644 index d852c86..0000000 --- a/Logger/initlog.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "logger.h" - -bool Logger::init(const QString &applicationPath, - const SettingStructure &settings) -{ - // test if log directory exists - _logPath = applicationPath + "/" + _logDirectory; - QDir logDir(_logPath); - if ( ! logDir.mkpath(".") ) - { - QTextStream(stdout) << "Failed to access log directory at " + _logPath << endl - << "Please create the director and/or apply relevant permissions." << endl; - return false; - } - - // log cycling -- determine log cycling setting - const QHash<QString, int> logCycling = { - {"never", 0}, - {"yearly", 1}, - {"monthly", 2}, - {"weekly", 3}, - {"daily", 4} - }; - - // load log-specific settings - _cyclePeriod = logCycling.value( settings.LoggingSettings.cycle ); - _suppressLog = settings.LoggingSettings.suppressLog; - _suppressDisplay = settings.LoggingSettings.suppressDisplay; - - // cycling initialisation ("never" is also a cycle) - if ( ! cycleLogFile() ) - { - QTextStream(stdout) << "Failed to access log file " + _logFileName + " at " + _logPath << endl; - return false; - } - return true; -} diff --git a/Logger/logevent.cpp b/Logger/logevent.cpp deleted file mode 100644 index 9d1858c..0000000 --- a/Logger/logevent.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "logger.h" - -void Logger::logEvent(const QString &messageType, - const QString &message) -{ - // printing to display suppressed? - if ( ! _suppressDisplay.contains(messageType) and ! _suppressDisplay.contains("all") ) - { - QString dateTimeStr(QDateTime::currentDateTime().toString("dd-MM-yyyy HH:mm:ss:zzz")); - logPrimitive() << QStringLiteral("[%1][%2]\t%3").arg(dateTimeStr, messageType, message.toLatin1()) << endl; - } - - // printing to logfile suppressed? - if ( ! _suppressLog.contains(messageType) and ! _suppressLog.contains("all") ) - { - // write message to log - QString dateTimeStr(QDateTime::currentDateTime().toString("dd-MM-yyyy HH:mm:ss:zzz")); - writeLogFile( QStringLiteral("[%1][%2]\t%3").arg(dateTimeStr, messageType, message.toLatin1()) ); - } -} diff --git a/Logger/logger.cpp b/Logger/logger.cpp deleted file mode 100644 index 3bf7def..0000000 --- a/Logger/logger.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "logger.h" - -Logger::Logger() -{ -} - -void Logger::stop() -{ - closeLogFile(); -} diff --git a/Logger/logger.h b/Logger/logger.h deleted file mode 100644 index 9880c44..0000000 --- a/Logger/logger.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef LOGGER_H -#define LOGGER_H - -#include <QDir> -#include <QFile> -#include <QDateTime> -#include <QTextStream> - -#include "Settings/settingstructure.h" -#include "Core/version.h" -#include "logprimitive.h" - -class Logger -{ -public: - Logger(); - bool init(const QString &applicationPath, - const SettingStructure &settings); - void stop(); - void logEvent(const QString &messageType, - const QString &message); - -private: - // path variables - const QString _logDirectory = "../log"; - const QString _logLabel = "MasterServer-" + SHORT_VER; - QString _logPath = ""; - - // local variables - int _cyclePeriod; - QString _logFileName; - QString _suppressLog; - QString _suppressDisplay; - - // file i/o - QFile _logFile; - -private: - bool cycleLogFile(); - bool openLogFile(); - void closeLogFile(); - bool writeLogFile(const QString message); - -}; - -#endif // LOGGER_H diff --git a/Logger/logprimitive.h b/Logger/logprimitive.h deleted file mode 100644 index 1630566..0000000 --- a/Logger/logprimitive.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef LOGPRIMITIVE_H -#define LOGPRIMITIVE_H - -#include <QTextStream> - -inline QTextStream& logPrimitive() -{ - static QTextStream r{stdout}; - return r; -} - -#endif // LOGPRIMITIVE_H diff --git a/Logger/openlogfile.cpp b/Logger/openlogfile.cpp deleted file mode 100644 index 349d058..0000000 --- a/Logger/openlogfile.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "logger.h" - -bool Logger::openLogFile() -{ - // verify that there is no open logfile already - if ( _logFile.openMode() == QIODevice::NotOpen) - { - // set new log file - _logFile.setFileName(_logPath + "/" + _logFileName); - return _logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text); - } - // else: - // file already open, can not get a lock - return false; -} - -void Logger::closeLogFile() -{ - // close file if open. if already closed, ignore. - _logFile.close(); -} diff --git a/Logger/writelogfile.cpp b/Logger/writelogfile.cpp deleted file mode 100644 index 954b5b2..0000000 --- a/Logger/writelogfile.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "logger.h" - -bool Logger::writeLogFile(const QString message) -{ - // first see if we need to cycle the log file already - cycleLogFile(); - - // write to file - if ( _logFile.isOpen() ) - { - QTextStream logStream(&_logFile); - logStream << message << endl; - return true; - } - - logPrimitive() << "[log error]" << message; - return false; -} |
