Overte C++ Documentation
LogHandler Class Reference

Handles custom message handling and sending of stats/logs to Logstash instance. More...

#include <LogHandler.h>

Inherits QObject.

Public Member Functions

bool parseOptions (const QString &options, const QString &paramName)
 Parse logging options. More...
 
void setTargetName (const QString &targetName)
 Set the name of the component that's producing log output. More...
 
void setShouldOutputProcessID (bool shouldOutputProcessID)
 Set whether to output the process ID. More...
 
void setShouldOutputThreadID (bool shouldOutputThreadID)
 Set whether to output the thread ID. More...
 
void setShouldDisplayMilliseconds (bool shouldDisplayMilliseconds)
 Set whether to display timestamps with milliseconds. More...
 
void setShouldUseJournald (bool shouldUseJournald)
 Set whether to use Journald, if it's available. More...
 
bool isJournaldAvailable () const
 Whether Journald is available on this version/system. More...
 
QString printMessage (LogMsgType type, const QMessageLogContext &context, const QString &message)
 Process a log message. More...
 

Static Public Member Functions

static LogHandlergetInstance ()
 Returns the one instance of the LogHandler object. More...
 
static void verboseMessageHandler (QtMsgType type, const QMessageLogContext &context, const QString &message)
 A qtMessageHandler that can be hooked up to a target that links to Qt. More...
 
static void breakOnMessage (const char *str)
 Break when a message that contains the specified string is logged. More...
 

Detailed Description

Handles custom message handling and sending of stats/logs to Logstash instance.

Member Function Documentation

◆ breakOnMessage()

void LogHandler::breakOnMessage ( const char *  str)
static

Break when a message that contains the specified string is logged.

This is a function intended to be invoked from inside a debugger. It should be of help when it's hard to put a breakpoint on the generating line because it comes from inlined code, or the interesting text is generated at runtime.

Example usage:

LogHandler::breakOnMessage("No instance available for");
static void breakOnMessage(const char *str)
Break when a message that contains the specified string is logged.
Definition: LogHandler.cpp:386

Then the debugger should be triggered as soon as a message containing that string is logged. Backtracking through the call stack should lead back to the source.

Note
Support for creating a breakpoint in software is compiler and OS specific. If there's no support for creating a breakpoint on the current compiler/OS, then an abort will be triggered instead.
Parameters
strText to match

◆ getInstance()

LogHandler & LogHandler::getInstance ( )
static

Returns the one instance of the LogHandler object.

Returns
LogHandler&

◆ isJournaldAvailable()

bool LogHandler::isJournaldAvailable ( ) const

Whether Journald is available on this version/system.

Support is available depending on compile options and only on Linux.

Returns
true Journald is available
false Journald is not available

◆ parseOptions()

bool LogHandler::parseOptions ( const QString &  options,
const QString &  paramName 
)

Parse logging options.

This parses the logging settings in the environment variable, or from the commandline

Parameters
optionsOption list
paramNameName of the log option, for error reporting.
Returns
true Option list was parsed successfully
false There was an error

◆ printMessage()

QString LogHandler::printMessage ( LogMsgType  type,
const QMessageLogContext &  context,
const QString &  message 
)

Process a log message.

This writes it to a file, logs it to the console, or sends it to journald.

Parameters
typeLog message type
contextContext of the log message (source file, line, function)
messageLog message
Returns
QString The log message's text with added severity and timestamp

◆ setShouldDisplayMilliseconds()

void LogHandler::setShouldDisplayMilliseconds ( bool  shouldDisplayMilliseconds)

Set whether to display timestamps with milliseconds.

Parameters
shouldDisplayMilliseconds

◆ setShouldOutputProcessID()

void LogHandler::setShouldOutputProcessID ( bool  shouldOutputProcessID)

Set whether to output the process ID.

Note
This has no effect when logging with journald, the PID is always logged
Parameters
shouldOutputProcessIDWhether to output the PID

◆ setShouldOutputThreadID()

void LogHandler::setShouldOutputThreadID ( bool  shouldOutputThreadID)

Set whether to output the thread ID.

Parameters
shouldOutputThreadID

◆ setShouldUseJournald()

void LogHandler::setShouldUseJournald ( bool  shouldUseJournald)

Set whether to use Journald, if it's available.

Parameters
shouldUseJournaldWhether to use journald

◆ setTargetName()

void LogHandler::setTargetName ( const QString &  targetName)

Set the name of the component that's producing log output.

For instance, "assignment-client", "audio-mixer", etc. Called once before logging begins

Parameters
targetNamethe desired target name to output in logs

◆ verboseMessageHandler()

void LogHandler::verboseMessageHandler ( QtMsgType  type,
const QMessageLogContext &  context,
const QString &  message 
)
static

A qtMessageHandler that can be hooked up to a target that links to Qt.

Prints various process, message type, and time information

Parameters
typeLog message type
contextContext of the log message (source file, line, function)
messageLog message

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