![]() |
AntiMicroX
|
Custom singleton class used for logging across application. More...
#include <logger.h>
Public Types | |
enum | LogLevel { LOG_NONE = 0, LOG_ERROR = 1, LOG_WARNING = 2, LOG_INFO = 3, LOG_VERBOSE = 4, LOG_DEBUG = 5, LOG_MAX = LOG_DEBUG } |
Public Slots | |
void | logMessage (const QString &message, const Logger::LogLevel level, const uint lineno, const QString &filename) |
Write an individual message to the text stream. More... | |
Public Member Functions | |
~Logger () | |
Close output stream and set instance to 0. More... | |
LogLevel | getCurrentLogLevel () |
Get the current output level associated with the logger. More... | |
bool | isWritingToFile () |
Static Public Member Functions | |
static void | loggerMessageHandler (QtMsgType type, const QMessageLogContext &context, const QString &msg) |
log message handling function More... | |
static void | setLogLevel (LogLevel level) |
Set the highest logging level. Determines which messages are output to the output stream. More... | |
static bool | isDebugEnabled () |
static void | setCurrentStream (QTextStream *stream) |
static void | setCurrentLogFile (QString filename) |
static QString | getCurrentLogFile () |
static QTextStream * | getCurrentStream () |
static Logger * | getInstance (bool raiseExceptionForNull=true) |
Get the Instance of logger. More... | |
static Logger * | createInstance (QTextStream *stream=nullptr, LogLevel outputLevel=LOG_INFO, QObject *parent=nullptr) |
Create instance of logger, if there is any other instance it will de deleted. More... | |
Protected Member Functions | |
Logger (QTextStream *stream, LogLevel output_lvl=LOG_INFO, QObject *parent=nullptr) | |
Outputs log messages to a given text stream. Client code should determine whether it points to a console stream or to a file. More... | |
void | closeLogger (bool closeStream=true) |
Flushes output stream and closes stream if requested. More... | |
Protected Attributes | |
QFile | outputFile |
QTextStream | outFileStream |
QTextStream * | outputStream |
LogLevel | outputLevel |
QMutex | logMutex |
QThread * | loggingThread |
Static Protected Attributes | |
static Logger * | instance = nullptr |
Custom singleton class used for logging across application.
It manages log-levels, formatting, printing logs and saving them to file. Logs across the program can be written using Local macros(better support for showing log location in release builds): DEBUG(), INFO(), VERBOSE(), WARN(), ERROR() QT macros: qDebug(), qInfo(), qWarning(), qCritical, and qFatal()
enum Logger::LogLevel |
Logger::~Logger | ( | ) |
Close output stream and set instance to 0.
|
explicitprotected |
Outputs log messages to a given text stream. Client code should determine whether it points to a console stream or to a file.
stream | used to output text |
output_lvl | Messages based of a given output level or lower will be logged |
parent | object |
|
protected |
Flushes output stream and closes stream if requested.
closeStream | Whether to close the current stream. Defaults to true. |
|
static |
Create instance of logger, if there is any other instance it will de deleted.
|
static |
Logger::LogLevel Logger::getCurrentLogLevel | ( | ) |
Get the current output level associated with the logger.
|
static |
|
inlinestatic |
Get the Instance of logger.
raiseExceptionForNull | - raise std::runtime_error when instance doesn't exist |
|
static |
bool Logger::isWritingToFile | ( | ) |
|
static |
log message handling function
It is meant to be registered via qInstallMessageHandler() at the beginning of application
type | |
context | |
msg |
|
slot |
Write an individual message to the text stream.
This socket method is executed in separate logging thread
|
static |
|
static |
Set the highest logging level. Determines which messages are output to the output stream.
level | Highest log level utilized. |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |