log.h
/*
*openPilotLog - A FOSS Pilot Logbook Application
*Copyright (C) 2020-2022 Felix Turowsky
*
*This program is free software: you can redistribute it and/or modify
*it under the terms of the GNU General Public License as published by
*the Free Software Foundation, either version 3 of the License, or
*(at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LOG_H
#define LOG_H
#include <QTime>
#include <QFile>
#include <QFileInfo>
#include <QDebug>
#include <QDir>
#include <QFileInfoList>
#include <iostream>
#include <QDebug>
namespace OPL::Log
{
static QDir logFolder;
static QString logFileName;
const static int numberOfLogs = 10; // max number of log files to keep
const static int sizeOfLogs = 1024 * 100; // max log size in bytes, = 100kB
const static auto DEB_HEADER = QLatin1String(" [DEBG]:\t");
const static auto INFO_HEADER = QLatin1String(" [INFO]:\t");
const static auto WARN_HEADER = QLatin1String(" [WARN]:\t");
const static auto CRIT_HEADER = QLatin1String(" [CRIT]:\t");
const static auto DEB_HEADER_CONSOLE = QLatin1String("\u001b[38;5;75m[DEBG]:\t");
const static auto INFO_HEADER_CONSOLE = QLatin1String("\033[32m[INFO]:\t\033[m");
const static auto WARN_HEADER_CONSOLE = QLatin1String("\033[33m[WARN]:\t\033[m");
const static auto CRIT_HEADER_CONSOLE = QLatin1String("\033[35m[CRIT]:\t\033[m");
const static auto SPACER = QLatin1String("\t\t");
const static auto D_SPACER = QLatin1String("\t\t\t\t");
bool init(bool log_debug = false);
void setLogFileName();
void deleteOldLogs();
void aMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString& msg);
inline static const QString timeNow(){return QTime::currentTime().toString(Qt::ISODate);}
} // namespace ALog
#define REPR(cls, str) \
friend \
QDebug operator<<(QDebug qdb, const cls& object) \
{ \
qdb << QString(#cls) + '(' + str + ')'; \
return qdb; \
}
#endif // LOG_H
OPL::Log
The OPL::Log namespace encapsulates constants and functions used to provide logging to files and logg...
Definition: log.cpp:23
OPL::Log::setLogFileName
void setLogFileName()
setLogFileName sets a log file name ("Log_<Date>_<Time>.txt")
Definition: log.cpp:30
OPL::Log::deleteOldLogs
void deleteOldLogs()
Cleans up old logs and initializes logging by preparing and installing a QMessageHandler.
Definition: log.cpp:41
OPL::Log::aMessageHandler
void aMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
aMessageHandler Intercepts Messages and prints to console and log file
Definition: log.cpp:94
OPL::Log::init
bool init(bool log_debug)
initialise logging, clean up logfiles and install a QMessageHandler. To enable logging of debug messa...
Definition: log.cpp:61