MythTV  master
mythlogging.h
Go to the documentation of this file.
1 #ifndef MYTHLOGGING_H_
2 #define MYTHLOGGING_H_
3 
4 #ifdef __cplusplus
5 #include <QString>
6 #include <QStringList>
7 #include <cstdint>
8 #include <cerrno>
9 #else
10 #include <stdint.h>
11 #include <errno.h>
12 #endif
13 
14 #include "mythbaseexp.h" // MBASE_PUBLIC , etc.
15 #include "verbosedefs.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 // Helper for checking verbose mask & level outside of LOG macro
22 #define VERBOSE_LEVEL_NONE (verboseMask == 0)
23 #ifdef __cplusplus
24 #define VERBOSE_LEVEL_CHECK(_MASK_, _LEVEL_) \
25  (componentLogLevel.contains(_MASK_) ? \
26  (*(componentLogLevel.find(_MASK_)) >= _LEVEL_) : \
27  (((verboseMask & (_MASK_)) == (_MASK_)) && logLevel >= (_LEVEL_)))
28 #else
29 #define VERBOSE_LEVEL_CHECK(_MASK_, _LEVEL_) \
30  (((verboseMask & (_MASK_)) == (_MASK_)) && logLevel >= (_LEVEL_))
31 #endif
32 
33 #define VERBOSE please_use_LOG_instead_of_VERBOSE
34 
35 // There are two LOG macros now. One for use with Qt/C++, one for use
36 // without Qt.
37 //
38 // Neither of them will lock the calling thread other than momentarily to put
39 // the log message onto a queue.
40 #ifdef __cplusplus
41 #define LOG(_MASK_, _LEVEL_, _STRING_) \
42  do { \
43  if (VERBOSE_LEVEL_CHECK((_MASK_), (_LEVEL_)) && ((_LEVEL_)>=0)) \
44  { \
45  LogPrintLine(_MASK_, _LEVEL_, \
46  __FILE__, __LINE__, __FUNCTION__, 1, \
47  qPrintable(_STRING_)); \
48  } \
49  } while (false)
50 #else
51 #define LOG(_MASK_, _LEVEL_, _FORMAT_, ...) \
52  do { \
53  if (VERBOSE_LEVEL_CHECK((_MASK_), (_LEVEL_)) && ((_LEVEL_)>=0)) \
54  { \
55  LogPrintLine(_MASK_, _LEVEL_, \
56  __FILE__, __LINE__, __FUNCTION__, 0, \
57  (const char *)_FORMAT_, ##__VA_ARGS__); \
58  } \
59  } while (0)
60 #endif
61 
62 /* Define the external prototype */
63 MBASE_PUBLIC void LogPrintLine( uint64_t mask, LogLevel_t level,
64  const char *file, int line,
65  const char *function, int fromQString,
66  const char *format, ... );
67 
68 extern MBASE_PUBLIC LogLevel_t logLevel;
69 extern MBASE_PUBLIC uint64_t verboseMask;
70 
71 #ifdef __cplusplus
73 }
74 
75 extern MBASE_PUBLIC QStringList logPropagateArgList;
76 extern MBASE_PUBLIC QString logPropagateArgs;
77 extern MBASE_PUBLIC QString verboseString;
78 
79 MBASE_PUBLIC void logStart(QString logfile, int progress = 0, int quiet = 0,
80  int facility = 0, LogLevel_t level = LOG_INFO,
81  bool dblog = true, bool propagate = false);
82 MBASE_PUBLIC void logStop(void);
85 
86 MBASE_PUBLIC int syslogGetFacility(QString facility);
87 MBASE_PUBLIC LogLevel_t logLevelGet(QString level);
88 MBASE_PUBLIC QString logLevelGetName(LogLevel_t level);
89 MBASE_PUBLIC int verboseArgParse(QString arg);
90 
92 MBASE_PUBLIC QString logStrerror(int errnum);
93 
99 #define ENO (QString("\n\t\t\teno: ") + logStrerror(errno))
100 #define ENO_STR ENO.toLocal8Bit().constData()
101 #endif // __cplusplus
102 
103 #endif
104 
105 /*
106  * vim:ts=4:sw=4:ai:et:si:sts=4
107  */
QString logfile
MBASE_PUBLIC void logStart(QString logfile, int progress=0, int quiet=0, int facility=0, LogLevel_t level=LOG_INFO, bool dblog=true, bool propagate=false)
Entry point to start logging for the application.
Definition: logging.cpp:726
MBASE_PUBLIC int syslogGetFacility(QString facility)
Map a syslog facility name back to the enumerated value.
Definition: logging.cpp:811
MBASE_PUBLIC uint64_t verboseMask
Definition: logging.cpp:107
QMap< uint64_t, LogLevel_t > ComponentLogLevelMap
Definition: verbosedefs.h:217
MBASE_PUBLIC QStringList logPropagateArgList
Definition: logging.cpp:90
MBASE_PUBLIC bool logPropagateQuiet(void)
Check if we are propagating a "--quiet".
Definition: logging.cpp:709
MBASE_PUBLIC QString logLevelGetName(LogLevel_t level)
Map a log level enumerated value back to the name.
Definition: logging.cpp:863
MBASE_PUBLIC ComponentLogLevelMap componentLogLevel
Definition: logging.cpp:109
MBASE_PUBLIC QString logStrerror(int errnum)
Verbose helper function for ENO macro.
Definition: logging.cpp:1117
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MBASE_PUBLIC void LogPrintLine(uint64_t mask, LogLevel_t level, const char *file, int line, const char *function, int fromQString, const char *format,...)
Format and send a log message into the queue.
Definition: logging.cpp:592
MBASE_PUBLIC void logPropagateCalc(void)
Generate the logPropagateArgs global with the latest logging level, mask, etc to propagate to all of ...
Definition: logging.cpp:653
MBASE_PUBLIC QString verboseString
Definition: logging.cpp:108
MBASE_PUBLIC LogLevel_t logLevel
Definition: logging.cpp:95
MBASE_PUBLIC int verboseArgParse(QString arg)
Parse the –verbose commandline argument and set the verbose level.
Definition: logging.cpp:990
MBASE_PUBLIC LogLevel_t logLevelGet(QString level)
Map a log level name back to the enumerated value.
Definition: logging.cpp:839
MBASE_PUBLIC QString logPropagateArgs
Definition: logging.cpp:89
MBASE_PUBLIC void logStop(void)
Entry point for stopping logging for an application.
Definition: logging.cpp:759