MythTV  master
Classes | Macros | Functions | Variables
logging.cpp File Reference
#include <QtGlobal>
#include <QAtomicInt>
#include <QMutex>
#include <QMutexLocker>
#include <QWaitCondition>
#include <QList>
#include <QQueue>
#include <QHash>
#include <QFileInfo>
#include <QStringList>
#include <QMap>
#include <QRegularExpression>
#include <QVariantMap>
#include <iostream>
#include "mythlogging.h"
#include "logging.h"
#include "loggingserver.h"
#include "mythdb.h"
#include "mythdirs.h"
#include "mythcorecontext.h"
#include "mythsystemlegacy.h"
#include "dbutil.h"
#include "exitcodes.h"
#include "compat.h"
#include <csignal>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <utility>
#include <unistd.h>
#include "verbosedefs.h"
Include dependency graph for logging.cpp:

Go to the source code of this file.

Classes

struct  LogPropagateOpts
 

Macros

#define SYSLOG_NAMES
 
#define MYTH_IMPLEMENT_VERBOSE
 

Functions

void verboseAdd (uint64_t mask, QString name, bool additive, QString helptext)
 Add a verbose level to the verboseMap. More...
 
void loglevelAdd (int value, QString name, char shortname)
 Add a log level to the logLevelMap. More...
 
void verboseInit (void)
 Initialize the logging levels and verbose levels. More...
 
void verboseHelp (void)
 Outputs the Verbose levels and their descriptions (for –verbose help) More...
 
void resetLogging (void)
 Intended for use only by the test harness. More...
 
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...
 
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...
 
bool logPropagateQuiet (void)
 Check if we are propagating a "--quiet". More...
 
void logStart (const QString &logfile, bool progress, int quiet, int facility, LogLevel_t level, bool propagate, bool testHarness)
 Entry point to start logging for the application. More...
 
void logStop (void)
 Entry point for stopping logging for an application. More...
 
void loggingRegisterThread (const QString &name)
 Register the current thread with the given name. More...
 
void loggingDeregisterThread (void)
 Deregister the current thread's name. More...
 
int syslogGetFacility ([[maybe_unused]] const QString &facility)
 Map a syslog facility name back to the enumerated value. More...
 
LogLevel_t logLevelGet (const QString &level)
 Map a log level name back to the enumerated value. More...
 
QString logLevelGetName (LogLevel_t level)
 Map a log level enumerated value back to the name. More...
 
int verboseArgParse (const QString &arg)
 Parse the –verbose commandline argument and set the verbose level. More...
 
QString logStrerror (int errnum)
 Verbose helper function for ENO macro. More...
 

Variables

static QMutex logQueueMutex
 
static QQueue< LoggingItem * > logQueue
 
static LoggerThreadlogThread = nullptr
 
static QMutex logThreadMutex
 
static QHash< uint64_t, QString > logThreadHash
 
static QMutex logThreadTidMutex
 
static QHash< uint64_t, int64_t > logThreadTidHash
 
static bool logThreadFinished = false
 
static bool debugRegistration = false
 
LogPropagateOpts logPropagateOpts {false, 0, 0, ""}
 
QString logPropagateArgs
 
QStringList logPropagateArgList
 
LogLevel_t logLevel = LOG_INFO
 
bool verboseInitialized = false
 
VerboseMap verboseMap
 
QMutex verboseMapMutex
 
LoglevelMap loglevelMap
 
QMutex loglevelMapMutex
 
const uint64_t verboseDefaultInt = VB_GENERAL
 
const QString verboseDefaultStr { QStringLiteral(" general") }
 
uint64_t verboseMask = verboseDefaultInt
 
QString verboseString = verboseDefaultStr
 
ComponentLogLevelMap componentLogLevel
 
uint64_t userDefaultValueInt = verboseDefaultInt
 
QString userDefaultValueStr = verboseDefaultStr
 
bool haveUserDefaultValues = false
 

Macro Definition Documentation

◆ SYSLOG_NAMES

#define SYSLOG_NAMES

Definition at line 39 of file logging.cpp.

◆ MYTH_IMPLEMENT_VERBOSE

#define MYTH_IMPLEMENT_VERBOSE

Function Documentation

◆ verboseAdd()

void verboseAdd ( uint64_t  mask,
QString  name,
bool  additive,
QString  helptext 
)

Add a verbose level to the verboseMap.

Done at initialization.

Parameters
maskverbose mask (VB_*)
namename of the verbosity level
additivetrue if this is to be ORed with other masks. false if is will clear the other bits.
helptextDescriptive text for –verbose help output

Definition at line 791 of file logging.cpp.

◆ loglevelAdd()

void loglevelAdd ( int  value,
QString  name,
char  shortname 
)

Add a log level to the logLevelMap.

Done at initialization.

Parameters
valuelog level enumerated value (LOG_*) - matches syslog levels
namename of the log level
shortnameone-letter short name for output into logs

Definition at line 811 of file logging.cpp.

◆ verboseInit()

void verboseInit ( void  )

Initialize the logging levels and verbose levels.

Definition at line 826 of file logging.cpp.

Referenced by logLevelGet(), logLevelGetName(), resetLogging(), and verboseArgParse().

◆ verboseHelp()

void verboseHelp ( void  )

Outputs the Verbose levels and their descriptions (for –verbose help)

Definition at line 851 of file logging.cpp.

Referenced by verboseArgParse().

◆ resetLogging()

void resetLogging ( void  )

Intended for use only by the test harness.

Definition at line 111 of file logging.cpp.

◆ LogPrintLine()

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 528 of file logging.cpp.

◆ logPropagateCalc()

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 572 of file logging.cpp.

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

◆ logPropagateQuiet()

bool logPropagateQuiet ( void  )

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

Returns
true if –quiet is being propagated

Definition at line 619 of file logging.cpp.

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

◆ logStart()

void logStart ( const QString &  logfile,
bool  progress,
int  quiet,
int  facility,
LogLevel_t  level,
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
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 637 of file logging.cpp.

Referenced by MythCommandLineParser::ConfigureLogging().

◆ logStop()

void logStop ( void  )

Entry point for stopping logging for an application.

Definition at line 669 of file logging.cpp.

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

◆ loggingRegisterThread()

void loggingRegisterThread ( const QString &  name)

Register the current thread with the given name.

This is triggered by the RunProlog() call in each thread.

Parameters
namethe name of the thread being registered. This is used for indicating the thread each log message is coming from.

Definition at line 684 of file logging.cpp.

Referenced by MPoolThread::run(), and MThread::ThreadSetup().

◆ loggingDeregisterThread()

void loggingDeregisterThread ( void  )

Deregister the current thread's name.

This is triggered by the RunEpilog() call in each thread.

Definition at line 703 of file logging.cpp.

Referenced by MPoolThread::run(), MThread::ThreadCleanup(), and MythCoreContextPrivate::~MythCoreContextPrivate().

◆ syslogGetFacility()

int syslogGetFacility ( [[maybe_unused] ] 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 721 of file logging.cpp.

Referenced by MythCommandLineParser::GetSyslogFacility().

◆ logLevelGet()

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 746 of file logging.cpp.

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

◆ logLevelGetName()

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 768 of file logging.cpp.

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

◆ verboseArgParse()

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 894 of file logging.cpp.

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

◆ logStrerror()

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 1019 of file logging.cpp.

Referenced by DVBChannel::DrainDVBEvents().

Variable Documentation

◆ logQueueMutex

QMutex logQueueMutex
static

◆ logQueue

QQueue<LoggingItem *> logQueue
static

◆ logThread

LoggerThread* logThread = nullptr
static

Definition at line 64 of file logging.cpp.

Referenced by LogPrintLine(), logStart(), and logStop().

◆ logThreadMutex

QMutex logThreadMutex
static

Definition at line 65 of file logging.cpp.

Referenced by LoggingItem::getThreadName(), and LoggerThread::handleItem().

◆ logThreadHash

QHash<uint64_t, QString> logThreadHash
static

Definition at line 66 of file logging.cpp.

Referenced by LoggingItem::getThreadName(), and LoggerThread::handleItem().

◆ logThreadTidMutex

QMutex logThreadTidMutex
static

◆ logThreadTidHash

QHash<uint64_t, int64_t> logThreadTidHash
static

◆ logThreadFinished

bool logThreadFinished = false
static

◆ debugRegistration

bool debugRegistration = false
static

Definition at line 72 of file logging.cpp.

Referenced by LoggerThread::handleItem(), and LoggerThread::LoggerThread().

◆ logPropagateOpts

LogPropagateOpts logPropagateOpts {false, 0, 0, ""}

Definition at line 81 of file logging.cpp.

Referenced by logPropagateCalc(), logPropagateQuiet(), and logStart().

◆ logPropagateArgs

QString logPropagateArgs

◆ logPropagateArgList

QStringList logPropagateArgList

Definition at line 83 of file logging.cpp.

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

◆ logLevel

LogLevel_t logLevel = LOG_INFO

◆ verboseInitialized

bool verboseInitialized = false

Definition at line 87 of file logging.cpp.

Referenced by logLevelGet(), logLevelGetName(), verboseArgParse(), and verboseInit().

◆ verboseMap

VerboseMap verboseMap

Definition at line 88 of file logging.cpp.

Referenced by verboseAdd(), verboseArgParse(), verboseHelp(), and verboseInit().

◆ verboseMapMutex

QMutex verboseMapMutex

Definition at line 89 of file logging.cpp.

Referenced by verboseArgParse(), and verboseInit().

◆ loglevelMap

LoglevelMap loglevelMap

◆ loglevelMapMutex

QMutex loglevelMapMutex

Definition at line 92 of file logging.cpp.

Referenced by LoggingItem::getLevelChar(), logLevelGet(), logLevelGetName(), and verboseInit().

◆ verboseDefaultInt

const uint64_t verboseDefaultInt = VB_GENERAL

Definition at line 94 of file logging.cpp.

Referenced by resetLogging(), and verboseArgParse().

◆ verboseDefaultStr

const QString verboseDefaultStr { QStringLiteral(" general") }

Definition at line 95 of file logging.cpp.

Referenced by resetLogging(), and verboseArgParse().

◆ verboseMask

uint64_t verboseMask = verboseDefaultInt

◆ verboseString

QString verboseString = verboseDefaultStr

◆ componentLogLevel

ComponentLogLevelMap componentLogLevel

Definition at line 99 of file logging.cpp.

Referenced by VERBOSE_LEVEL_CHECK(), and verboseArgParse().

◆ userDefaultValueInt

uint64_t userDefaultValueInt = verboseDefaultInt

Definition at line 101 of file logging.cpp.

Referenced by resetLogging(), and verboseArgParse().

◆ userDefaultValueStr

QString userDefaultValueStr = verboseDefaultStr

Definition at line 102 of file logging.cpp.

Referenced by resetLogging(), verboseArgParse(), and verboseHelp().

◆ haveUserDefaultValues

bool haveUserDefaultValues = false

Definition at line 103 of file logging.cpp.

Referenced by resetLogging(), and verboseArgParse().