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 // Helper for checking verbose mask & level outside of LOG macro
13 #define VERBOSE_LEVEL_NONE (verboseMask == 0)
14 #define VERBOSE_LEVEL_CHECK(_MASK_, _LEVEL_) \
15  (componentLogLevel.contains(_MASK_) ? \
16  (*(componentLogLevel.find(_MASK_)) >= (_LEVEL_)) : \
17  (((verboseMask & (_MASK_)) == (_MASK_)) && logLevel >= (_LEVEL_)))
18 
19 #define VERBOSE please_use_LOG_instead_of_VERBOSE
20 
21 // This doesn't lock the calling thread other than momentarily to put
22 // the log message onto a queue.
23 #define LOG(_MASK_, _LEVEL_, _QSTRING_) \
24  do { \
25  if (VERBOSE_LEVEL_CHECK((_MASK_), (_LEVEL_)) && ((_LEVEL_)>=0)) \
26  { \
27  LogPrintLine(_MASK_, _LEVEL_, \
28  __FILE__, __LINE__, __FUNCTION__, \
29  _QSTRING_); \
30  } \
31  } while (false)
32 
33 /* Define the external prototype */
34 MBASE_PUBLIC void LogPrintLine( uint64_t mask, LogLevel_t level,
35  const char *file, int line,
36  const char *function,
37  QString message);
38 
39 extern MBASE_PUBLIC LogLevel_t logLevel;
40 extern MBASE_PUBLIC uint64_t verboseMask;
41 
43 
44 extern MBASE_PUBLIC QStringList logPropagateArgList;
45 extern MBASE_PUBLIC QString logPropagateArgs;
46 extern MBASE_PUBLIC QString verboseString;
47 
48 MBASE_PUBLIC void resetLogging(void);
49 
50 MBASE_PUBLIC void logStart(const QString& logfile, bool progress = false,
51  int quiet = 0,
52  int facility = 0, LogLevel_t level = LOG_INFO,
53  bool dblog = true, bool propagate = false,
54  bool testHarness = false);
55 MBASE_PUBLIC void logStop(void);
58 
59 MBASE_PUBLIC int syslogGetFacility(const QString& facility);
60 MBASE_PUBLIC LogLevel_t logLevelGet(const QString& level);
61 MBASE_PUBLIC QString logLevelGetName(LogLevel_t level);
62 MBASE_PUBLIC int verboseArgParse(const QString& arg);
63 
65 MBASE_PUBLIC QString logStrerror(int errnum);
66 
72 #define ENO (QString("\n\t\t\teno: ") + logStrerror(errno))
73 #define ENO_STR ENO.toLocal8Bit().constData()
74 
75 #endif
76 
77 /*
78  * vim:ts=4:sw=4:ai:et:si:sts=4
79  */
resetLogging
MBASE_PUBLIC void resetLogging(void)
Intended for use only by the test harness.
Definition: logging.cpp:116
verboseString
MBASE_PUBLIC QString verboseString
Definition: logging.cpp:103
mythbaseexp.h
progress
bool progress
Definition: mythtv/programs/mythcommflag/main.cpp:73
arg
arg(title).arg(filename).arg(doDelete))
logLevelGetName
MBASE_PUBLIC QString logLevelGetName(LogLevel_t level)
Map a log level enumerated value back to the name.
Definition: logging.cpp:839
verbosedefs.h
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:586
logStop
MBASE_PUBLIC void logStop(void)
Entry point for stopping logging for an application.
Definition: logging.cpp:737
logPropagateArgList
MBASE_PUBLIC QStringList logPropagateArgList
Definition: logging.cpp:88
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
logfile
QString logfile
Definition: backendcontext.cpp:14
quiet
int quiet
Definition: mythtv/programs/mythcommflag/main.cpp:72
logPropagateArgs
MBASE_PUBLIC QString logPropagateArgs
Definition: logging.cpp:87
componentLogLevel
MBASE_PUBLIC ComponentLogLevelMap componentLogLevel
Definition: logging.cpp:104
logPropagateQuiet
MBASE_PUBLIC bool logPropagateQuiet(void)
Check if we are propagating a "--quiet".
Definition: logging.cpp:683
logLevelGet
MBASE_PUBLIC LogLevel_t logLevelGet(const QString &level)
Map a log level name back to the enumerated value.
Definition: logging.cpp:817
logLevel
MBASE_PUBLIC LogLevel_t logLevel
Definition: logging.cpp:90
logStrerror
MBASE_PUBLIC QString logStrerror(int errnum)
Verbose helper function for ENO macro.
Definition: logging.cpp:1095
ComponentLogLevelMap
QMap< uint64_t, LogLevel_t > ComponentLogLevelMap
Definition: verbosedefs.h:217
syslogGetFacility
MBASE_PUBLIC int syslogGetFacility(const QString &facility)
Map a syslog facility name back to the enumerated value.
Definition: logging.cpp:789
logStart
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.
Definition: logging.cpp:702
verboseMask
MBASE_PUBLIC uint64_t verboseMask
Definition: logging.cpp:102
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:630
verboseArgParse
MBASE_PUBLIC int verboseArgParse(const QString &arg)
Parse the –verbose commandline argument and set the verbose level.
Definition: logging.cpp:965