MythTV  master
Macros | Functions | Variables
mythlogging.h File Reference
#include <QString>
#include <QStringList>
#include <cstdint>
#include <cerrno>
#include "mythbaseexp.h"
#include "verbosedefs.h"
Include dependency graph for mythlogging.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define VERBOSE_LEVEL_NONE   (verboseMask == 0)
 
#define VERBOSE_LEVEL_CHECK(_MASK_, _LEVEL_)
 
#define VERBOSE   please_use_LOG_instead_of_VERBOSE
 
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
 
#define ENO   (QString("\n\t\t\teno: ") + logStrerror(errno))
 This can be appended to the LOG args with "+". More...
 
#define ENO_STR   ENO.toLocal8Bit().constData()
 

Functions

MBASE_PUBLIC void LogPrintLine (uint64_t mask, LogLevel_t level, const char *file, int line, const char *function, QString message)
 Format and send a log message into the queue. More...
 
MBASE_PUBLIC void resetLogging (void)
 Intended for use only by the test harness. More...
 
MBASE_PUBLIC void logStart (const QString &logfile, bool progress=false, int quiet=0, int facility=0, LogLevel_t level=LOG_INFO, bool dblog=true, bool propagate=false, bool testHarness=false)
 Entry point to start logging for the application. More...
 
MBASE_PUBLIC void logStop (void)
 Entry point for stopping logging for an application. More...
 
MBASE_PUBLIC void logPropagateCalc (void)
 Generate the logPropagateArgs global with the latest logging level, mask, etc to propagate to all of the mythtv programs spawned from this one. More...
 
MBASE_PUBLIC bool logPropagateQuiet (void)
 Check if we are propagating a "--quiet". More...
 
MBASE_PUBLIC int syslogGetFacility (const QString &facility)
 Map a syslog facility name back to the enumerated value. More...
 
MBASE_PUBLIC LogLevel_t logLevelGet (const QString &level)
 Map a log level name back to the enumerated value. More...
 
MBASE_PUBLIC QString logLevelGetName (LogLevel_t level)
 Map a log level enumerated value back to the name. More...
 
MBASE_PUBLIC int verboseArgParse (const QString &arg)
 Parse the –verbose commandline argument and set the verbose level. More...
 
MBASE_PUBLIC QString logStrerror (int errnum)
 Verbose helper function for ENO macro. More...
 

Variables

MBASE_PUBLIC LogLevel_t logLevel
 
MBASE_PUBLIC uint64_t verboseMask
 
MBASE_PUBLIC ComponentLogLevelMap componentLogLevel
 
MBASE_PUBLIC QStringList logPropagateArgList
 
MBASE_PUBLIC QString logPropagateArgs
 
MBASE_PUBLIC QString verboseString
 

Macro Definition Documentation

◆ VERBOSE_LEVEL_NONE

#define VERBOSE_LEVEL_NONE   (verboseMask == 0)

Definition at line 14 of file mythlogging.h.

◆ VERBOSE_LEVEL_CHECK

#define VERBOSE_LEVEL_CHECK (   _MASK_,
  _LEVEL_ 
)
Value:
(componentLogLevel.contains(_MASK_) ? \
(*(componentLogLevel.find(_MASK_)) >= (_LEVEL_)) : \
(((verboseMask & (_MASK_)) == (_MASK_)) && logLevel >= (_LEVEL_)))

Definition at line 15 of file mythlogging.h.

◆ VERBOSE

#define VERBOSE   please_use_LOG_instead_of_VERBOSE

Definition at line 20 of file mythlogging.h.

◆ LOG

#define LOG (   _MASK_,
  _LEVEL_,
  _QSTRING_ 
)
Value:
do { \
if (VERBOSE_LEVEL_CHECK((_MASK_), (_LEVEL_)) && ((_LEVEL_)>=0)) \
{ \
LogPrintLine(_MASK_, _LEVEL_, \
__FILE__, __LINE__, __FUNCTION__, \
_QSTRING_); \
} \
} while (false)

Definition at line 24 of file mythlogging.h.

◆ ENO

#define ENO   (QString("\n\t\t\teno: ") + logStrerror(errno))

This can be appended to the LOG args with "+".

Please do not use "<<". It uses a thread safe version of strerror to produce the string representation of errno and puts it on the next line in the verbose output.

Definition at line 73 of file mythlogging.h.

◆ ENO_STR

#define ENO_STR   ENO.toLocal8Bit().constData()

Definition at line 74 of file mythlogging.h.

Function Documentation

◆ LogPrintLine()

MBASE_PUBLIC void LogPrintLine ( uint64_t  mask,
LogLevel_t  level,
const char *  file,
int  line,
const char *  function,
QString  message 
)

Format and send a log message into the queue.

This is called from the LOG() macro. The intention is minimal blocking of the caller.

Parameters
maskVerbosity mask of the message (VB_*)
levelLog level of this message (LOG_* - matching syslog levels)
fileFilename of source code logging the message
lineLine number within the source of log message source
functionFunction name of the log message source
messagelog message

Definition at line 83 of file logging.cpp.

◆ resetLogging()

MBASE_PUBLIC void resetLogging ( void  )

Intended for use only by the test harness.

Definition at line 118 of file logging.cpp.

◆ logStart()

MBASE_PUBLIC void logStart ( const QString &  logfile,
bool  progress,
int  quiet,
int  facility,
LogLevel_t  level,
bool  dblog,
bool  propagate,
bool  testHarness 
)

Entry point to start logging for the application.

This will start up all of the threads needed.

Parameters
logfileFilename of the logfile to create. Empty if no file.
progressnon-zero if progress output will be sent to the console. This squelches all messages less important than LOG_ERR on the console
quietquiet level requested (squelches all console output)
facilitySyslog facility to use. -1 to disable syslog output
levelMinimum logging level to put into the logs
dblogtrue if database logging is requested
propagatetrue if the logfile path needs to be propagated to child processes.
testHarnessShould always be false. Set to true when invoked by the testing code.

Definition at line 720 of file logging.cpp.

Referenced by MythCommandLineParser::ConfigureLogging().

◆ logStop()

MBASE_PUBLIC void logStop ( void  )

Entry point for stopping logging for an application.

Definition at line 755 of file logging.cpp.

Referenced by main(), MythContext::~MythContext(), and MythCoreContextPrivate::~MythCoreContextPrivate().

◆ logPropagateCalc()

MBASE_PUBLIC void logPropagateCalc ( void  )

Generate the logPropagateArgs global with the latest logging level, mask, etc to propagate to all of the mythtv programs spawned from this one.

Definition at line 648 of file logging.cpp.

Referenced by MainServer::HandleSetLogLevel(), MainServer::HandleSetVerbose(), and logStart().

◆ logPropagateQuiet()

MBASE_PUBLIC bool logPropagateQuiet ( void  )

Check if we are propagating a "--quiet".

Returns
true if –quiet is being propagated

Definition at line 701 of file logging.cpp.

Referenced by BurnMenu::doBurn(), getFileDetails(), and MythSystemLegacy::SetCommand().

◆ syslogGetFacility()

MBASE_PUBLIC int syslogGetFacility ( const QString &  facility)

Map a syslog facility name back to the enumerated value.

Parameters
facilityQString containing the facility name
Returns
Syslog facility as enumerated type. Negative if not found.

Definition at line 807 of file logging.cpp.

Referenced by MythCommandLineParser::GetSyslogFacility().

◆ logLevelGet()

MBASE_PUBLIC LogLevel_t logLevelGet ( const QString &  level)

Map a log level name back to the enumerated value.

Parameters
levelQString containing the log level name
Returns
Log level as enumerated type. LOG_UNKNOWN if not found.

Definition at line 835 of file logging.cpp.

Referenced by MythCommandLineParser::GetLogLevel(), Myth::GetLogs(), MainServer::HandleSetLogLevel(), and verboseArgParse().

◆ logLevelGetName()

MBASE_PUBLIC QString logLevelGetName ( LogLevel_t  level)

Map a log level enumerated value back to the name.

Parameters
levelEnumerated value of the log level
Returns
Log level name. "unknown" if not found.

Definition at line 857 of file logging.cpp.

Referenced by MythCommandLineParser::addLogging(), Myth::GetLogs(), MainServer::HandleSetLogLevel(), logPropagateCalc(), and logStart().

◆ verboseArgParse()

MBASE_PUBLIC int verboseArgParse ( const QString &  arg)

Parse the –verbose commandline argument and set the verbose level.

Parameters
argthe commandline argument following "--verbose"
Returns
an exit code. GENERIC_EXIT_OK if all is well.

Definition at line 982 of file logging.cpp.

Referenced by MythCommandLineParser::ConfigureLogging(), MainServer::HandleSetVerbose(), and NetworkControl::processSet().

◆ logStrerror()

MBASE_PUBLIC QString logStrerror ( int  errnum)

Verbose helper function for ENO macro.

Parameters
errnumsystem errno value
Returns
QString containing the string version of the errno value, plus the errno value itself.

Definition at line 1112 of file logging.cpp.

Variable Documentation

◆ logLevel

MBASE_PUBLIC LogLevel_t logLevel

◆ verboseMask

MBASE_PUBLIC uint64_t verboseMask

◆ componentLogLevel

Definition at line 106 of file logging.cpp.

Referenced by verboseArgParse().

◆ logPropagateArgList

MBASE_PUBLIC QStringList logPropagateArgList

Definition at line 90 of file logging.cpp.

Referenced by logPropagateCalc(), and MythSystemLegacy::SetCommand().

◆ logPropagateArgs

MBASE_PUBLIC QString logPropagateArgs

◆ verboseString

MBASE_PUBLIC QString verboseString
componentLogLevel
MBASE_PUBLIC ComponentLogLevelMap componentLogLevel
Definition: logging.cpp:106
VERBOSE_LEVEL_CHECK
#define VERBOSE_LEVEL_CHECK(_MASK_, _LEVEL_)
Definition: mythlogging.h:14
logLevel
MBASE_PUBLIC LogLevel_t logLevel
Definition: logging.cpp:92
verboseMask
MBASE_PUBLIC uint64_t verboseMask
Definition: logging.cpp:104