MythTV  master
mythlogging.h
Go to the documentation of this file.
1 #ifndef MYTHLOGGING_H_
2 #define MYTHLOGGING_H_
3 
4 #include <QString>
5 #include <QStringList>
6 #include <cstdint>
7 #include <cerrno>
8 
9 #include "mythbaseexp.h" // MBASE_PUBLIC , etc.
10 #include "verbosedefs.h"
11 
12 /* Define the external prototype */
13 MBASE_PUBLIC void LogPrintLine( uint64_t mask, LogLevel_t level,
14  const char *file, int line,
15  const char *function,
16  QString message);
17 
18 extern MBASE_PUBLIC LogLevel_t logLevel;
19 extern MBASE_PUBLIC uint64_t verboseMask;
20 
22 
23 extern MBASE_PUBLIC QStringList logPropagateArgList;
24 extern MBASE_PUBLIC QString logPropagateArgs;
25 extern MBASE_PUBLIC QString verboseString;
26 
27 // Helper for checking verbose mask & level outside of LOG macro
28 static inline bool VERBOSE_LEVEL_NONE() { return verboseMask == 0; };
29 static inline bool VERBOSE_LEVEL_CHECK(uint64_t mask, LogLevel_t level)
30 {
31  if (componentLogLevel.contains(mask))
32  return *(componentLogLevel.find(mask)) >= level;
33  return (((verboseMask & mask) == mask) && (logLevel >= level));
34 }
35 
36 // This doesn't lock the calling thread other than momentarily to put
37 // the log message onto a queue.
38 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
39 #define LOG(_MASK_, _LEVEL_, _QSTRING_) \
40  do { \
41  if (VERBOSE_LEVEL_CHECK((_MASK_), (_LEVEL_)) && ((_LEVEL_)>=0)) \
42  { \
43  LogPrintLine(_MASK_, _LEVEL_, \
44  __FILE__, __LINE__, __FUNCTION__, \
45  _QSTRING_); \
46  } \
47  } while (false)
48 
49 MBASE_PUBLIC void resetLogging(void);
50 
51 MBASE_PUBLIC void logStart(const QString& logfile, bool progress = false,
52  int quiet = 0,
53  int facility = 0, LogLevel_t level = LOG_INFO,
54  bool propagate = false,
55  bool testHarness = false);
56 MBASE_PUBLIC void logStop(void);
59 
60 MBASE_PUBLIC int syslogGetFacility(const QString& facility);
61 MBASE_PUBLIC LogLevel_t logLevelGet(const QString& level);
62 MBASE_PUBLIC QString logLevelGetName(LogLevel_t level);
63 MBASE_PUBLIC int verboseArgParse(const QString& arg);
64 
66 MBASE_PUBLIC QString logStrerror(int errnum);
67 
73 #define ENO (QString("\n\t\t\teno: ") + logStrerror(errno))
74 #define ENO_STR ENO.toLocal8Bit().constData()
75 
76 #endif
77 
78 /*
79  * vim:ts=4:sw=4:ai:et:si:sts=4
80  */
resetLogging
MBASE_PUBLIC void resetLogging(void)
Intended for use only by the test harness.
Definition: logging.cpp:111
verboseString
MBASE_PUBLIC QString verboseString
Definition: logging.cpp:98
progress
bool progress
Definition: mythcommflag.cpp:69
mythbaseexp.h
VERBOSE_LEVEL_CHECK
static bool VERBOSE_LEVEL_CHECK(uint64_t mask, LogLevel_t level)
Definition: mythlogging.h:29
logLevelGetName
MBASE_PUBLIC QString logLevelGetName(LogLevel_t level)
Map a log level enumerated value back to the name.
Definition: logging.cpp:768
quiet
int quiet
Definition: mythcommflag.cpp:68
verbosedefs.h
logfile
QString logfile
Definition: mythjobqueue.cpp:45
logStart
MBASE_PUBLIC void logStart(const QString &logfile, bool progress=false, int quiet=0, int facility=0, LogLevel_t level=LOG_INFO, bool propagate=false, bool testHarness=false)
Entry point to start logging for the application.
Definition: logging.cpp:637
build_compdb.file
file
Definition: build_compdb.py:55
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.
Definition: logging.cpp:528
logStop
MBASE_PUBLIC void logStop(void)
Entry point for stopping logging for an application.
Definition: logging.cpp:669
logPropagateArgList
MBASE_PUBLIC QStringList logPropagateArgList
Definition: logging.cpp:83
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
logPropagateArgs
MBASE_PUBLIC QString logPropagateArgs
Definition: logging.cpp:82
componentLogLevel
MBASE_PUBLIC ComponentLogLevelMap componentLogLevel
Definition: logging.cpp:99
logPropagateQuiet
MBASE_PUBLIC bool logPropagateQuiet(void)
Check if we are propagating a "--quiet".
Definition: logging.cpp:619
logLevelGet
MBASE_PUBLIC LogLevel_t logLevelGet(const QString &level)
Map a log level name back to the enumerated value.
Definition: logging.cpp:746
logLevel
MBASE_PUBLIC LogLevel_t logLevel
Definition: logging.cpp:85
logStrerror
MBASE_PUBLIC QString logStrerror(int errnum)
Verbose helper function for ENO macro.
Definition: logging.cpp:1019
ComponentLogLevelMap
QMap< uint64_t, LogLevel_t > ComponentLogLevelMap
Definition: verbosedefs.h:221
syslogGetFacility
MBASE_PUBLIC int syslogGetFacility(const QString &facility)
VERBOSE_LEVEL_NONE
static bool VERBOSE_LEVEL_NONE()
Definition: mythlogging.h:28
verboseMask
MBASE_PUBLIC uint64_t verboseMask
Definition: logging.cpp:97
logPropagateCalc
MBASE_PUBLIC void logPropagateCalc(void)
Generate the logPropagateArgs global with the latest logging level, mask, etc to propagate to all of ...
Definition: logging.cpp:572
verboseArgParse
MBASE_PUBLIC int verboseArgParse(const QString &arg)
Parse the –verbose commandline argument and set the verbose level.
Definition: logging.cpp:894