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 loglong = false,
56  bool testHarness = false);
57 MBASE_PUBLIC void logStop(void);
60 
61 MBASE_PUBLIC int syslogGetFacility(const QString& facility);
62 MBASE_PUBLIC LogLevel_t logLevelGet(const QString& level);
63 MBASE_PUBLIC QString logLevelGetName(LogLevel_t level);
64 MBASE_PUBLIC int verboseArgParse(const QString& arg);
65 
67 MBASE_PUBLIC QString logStrerror(int errnum);
68 
74 #define ENO (QString("\n\t\t\teno: ") + logStrerror(errno))
75 #define ENO_STR ENO.toLocal8Bit().constData()
76 
77 inline QString pointerToQString(const void *p)
78 {
79  return QStringLiteral("0x%1").arg(reinterpret_cast<quintptr>(p),
80  sizeof(void*) * 2, 16, QChar('0'));
81 }
82 
83 #endif
84 
85 /*
86  * vim:ts=4:sw=4:ai:et:si:sts=4
87  */
resetLogging
MBASE_PUBLIC void resetLogging(void)
Intended for use only by the test harness.
Definition: logging.cpp:112
verboseString
MBASE_PUBLIC QString verboseString
Definition: logging.cpp:99
progress
bool progress
Definition: mythcommflag.cpp:69
mythbaseexp.h
pointerToQString
QString pointerToQString(const void *p)
Definition: mythlogging.h:77
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 loglong=false, bool testHarness=false)
Entry point to start logging for the application.
Definition: logging.cpp:653
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:785
quiet
int quiet
Definition: mythcommflag.cpp:68
verbosedefs.h
logfile
QString logfile
Definition: mythjobqueue.cpp:45
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:538
logStop
MBASE_PUBLIC void logStop(void)
Entry point for stopping logging for an application.
Definition: logging.cpp:686
logPropagateArgList
MBASE_PUBLIC QStringList logPropagateArgList
Definition: logging.cpp:84
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
hardwareprofile.config.p
p
Definition: config.py:33
logPropagateArgs
MBASE_PUBLIC QString logPropagateArgs
Definition: logging.cpp:83
componentLogLevel
MBASE_PUBLIC ComponentLogLevelMap componentLogLevel
Definition: logging.cpp:100
logPropagateQuiet
MBASE_PUBLIC bool logPropagateQuiet(void)
Check if we are propagating a "--quiet".
Definition: logging.cpp:635
logLevelGet
MBASE_PUBLIC LogLevel_t logLevelGet(const QString &level)
Map a log level name back to the enumerated value.
Definition: logging.cpp:763
logLevel
MBASE_PUBLIC LogLevel_t logLevel
Definition: logging.cpp:86
logStrerror
MBASE_PUBLIC QString logStrerror(int errnum)
Verbose helper function for ENO macro.
Definition: logging.cpp:1036
ComponentLogLevelMap
QMap< uint64_t, LogLevel_t > ComponentLogLevelMap
Definition: verbosedefs.h:222
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:98
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:582
verboseArgParse
MBASE_PUBLIC int verboseArgParse(const QString &arg)
Parse the –verbose commandline argument and set the verbose level.
Definition: logging.cpp:911