AntiMicroX
Public Types | Public Slots | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
Logger Class Reference

Custom singleton class used for logging across application. More...

#include <logger.h>

Inheritance diagram for Logger:
[legend]
Collaboration diagram for Logger:
[legend]

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 LoggergetInstance (bool raiseExceptionForNull=true)
 Get the Instance of logger. More...
 
static LoggercreateInstance (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 Loggerinstance = nullptr
 

Detailed Description

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()

Member Enumeration Documentation

◆ LogLevel

Enumerator
LOG_NONE 
LOG_ERROR 
LOG_WARNING 
LOG_INFO 
LOG_VERBOSE 
LOG_DEBUG 
LOG_MAX 

Constructor & Destructor Documentation

◆ ~Logger()

Logger::~Logger ( )

Close output stream and set instance to 0.

Here is the call graph for this function:

◆ Logger()

Logger::Logger ( QTextStream *  stream,
LogLevel  output_lvl = LOG_INFO,
QObject *  parent = nullptr 
)
explicitprotected

Outputs log messages to a given text stream. Client code should determine whether it points to a console stream or to a file.

Parameters
streamused to output text
output_lvlMessages based of a given output level or lower will be logged
parentobject
Here is the caller graph for this function:

Member Function Documentation

◆ closeLogger()

void Logger::closeLogger ( bool  closeStream = true)
protected

Flushes output stream and closes stream if requested.

Parameters
closeStreamWhether to close the current stream. Defaults to true.
Here is the caller graph for this function:

◆ createInstance()

Logger * Logger::createInstance ( QTextStream *  stream = nullptr,
LogLevel  outputLevel = LOG_INFO,
QObject *  parent = nullptr 
)
static

Create instance of logger, if there is any other instance it will de deleted.

Returns
Logger* - pointer to newly created instance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCurrentLogFile()

QString Logger::getCurrentLogFile ( )
static

◆ getCurrentLogLevel()

Logger::LogLevel Logger::getCurrentLogLevel ( )

Get the current output level associated with the logger.

Returns
Current output level
Here is the caller graph for this function:

◆ getCurrentStream()

QTextStream * Logger::getCurrentStream ( )
static

◆ getInstance()

static Logger* Logger::getInstance ( bool  raiseExceptionForNull = true)
inlinestatic

Get the Instance of logger.

Parameters
raiseExceptionForNull- raise std::runtime_error when instance doesn't exist
Returns
Logger*
Here is the caller graph for this function:

◆ isDebugEnabled()

bool Logger::isDebugEnabled ( )
static
Here is the caller graph for this function:

◆ isWritingToFile()

bool Logger::isWritingToFile ( )

◆ loggerMessageHandler()

void Logger::loggerMessageHandler ( QtMsgType  type,
const QMessageLogContext &  context,
const QString &  msg 
)
static

log message handling function

It is meant to be registered via qInstallMessageHandler() at the beginning of application

Parameters
type
context
msg
Here is the call graph for this function:
Here is the caller graph for this function:

◆ logMessage

void Logger::logMessage ( const QString &  message,
const Logger::LogLevel  level,
const uint  lineno,
const QString &  filename 
)
slot

Write an individual message to the text stream.

This socket method is executed in separate logging thread

Here is the caller graph for this function:

◆ setCurrentLogFile()

void Logger::setCurrentLogFile ( QString  filename)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCurrentStream()

void Logger::setCurrentStream ( QTextStream *  stream)
static
Here is the caller graph for this function:

◆ setLogLevel()

void Logger::setLogLevel ( LogLevel  level)
static

Set the highest logging level. Determines which messages are output to the output stream.

Parameters
levelHighest log level utilized.
Here is the caller graph for this function:

Field Documentation

◆ instance

Logger * Logger::instance = nullptr
staticprotected

◆ loggingThread

QThread* Logger::loggingThread
protected

◆ logMutex

QMutex Logger::logMutex
protected

◆ outFileStream

QTextStream Logger::outFileStream
protected

◆ outputFile

QFile Logger::outputFile
protected

◆ outputLevel

LogLevel Logger::outputLevel
protected

◆ outputStream

QTextStream* Logger::outputStream
protected

The documentation for this class was generated from the following files: