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 */
13MBASE_PUBLIC void LogPrintLine( uint64_t mask, LogLevel_t level,
14 const char *file, int line,
15 const char *function,
16 QString message);
17
18extern MBASE_PUBLIC LogLevel_t logLevel;
19extern MBASE_PUBLIC uint64_t verboseMask;
20
22
23extern MBASE_PUBLIC QStringList logPropagateArgList;
24extern MBASE_PUBLIC QString logPropagateArgs;
25extern MBASE_PUBLIC QString verboseString;
26
27// Helper for checking verbose mask & level outside of LOG macro
28static inline bool VERBOSE_LEVEL_NONE() { return verboseMask == 0; };
29static 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
49MBASE_PUBLIC void resetLogging(void);
50
51MBASE_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);
57MBASE_PUBLIC void logStop(void);
60
61MBASE_PUBLIC int syslogGetFacility(const QString& facility);
62MBASE_PUBLIC LogLevel_t logLevelGet(const QString& level);
63MBASE_PUBLIC QString logLevelGetName(LogLevel_t level);
64MBASE_PUBLIC int verboseArgParse(const QString& arg);
65
67MBASE_PUBLIC QString logStrerror(int errnum);
68
74#define ENO (QString("\n\t\t\teno: ") + logStrerror(errno))
75#define ENO_STR ENO.toLocal8Bit().constData()
76
77inline 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
86inline QString boolToQString(bool val)
87{
88 return (val) ? QStringLiteral("true") : QStringLiteral("false");
89}
90
91#endif
92
93/*
94 * vim:ts=4:sw=4:ai:et:si:sts=4
95 */
#define MBASE_PUBLIC
Definition: mythbaseexp.h:8
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:537
MBASE_PUBLIC QString logLevelGetName(LogLevel_t level)
Map a log level enumerated value back to the name.
Definition: logging.cpp:788
MBASE_PUBLIC LogLevel_t logLevelGet(const QString &level)
Map a log level name back to the enumerated value.
Definition: logging.cpp:766
MBASE_PUBLIC int verboseArgParse(const QString &arg)
Parse the –verbose commandline argument and set the verbose level.
Definition: logging.cpp:916
MBASE_PUBLIC bool logPropagateQuiet(void)
Check if we are propagating a "--quiet".
Definition: logging.cpp:634
static bool VERBOSE_LEVEL_CHECK(uint64_t mask, LogLevel_t level)
Definition: mythlogging.h:29
MBASE_PUBLIC QStringList logPropagateArgList
Definition: logging.cpp:83
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:652
MBASE_PUBLIC QString logStrerror(int errnum)
Verbose helper function for ENO macro.
Definition: logging.cpp:1041
MBASE_PUBLIC QString verboseString
Definition: logging.cpp:98
QString pointerToQString(const void *p)
Definition: mythlogging.h:77
MBASE_PUBLIC LogLevel_t logLevel
Definition: logging.cpp:85
QString boolToQString(bool val)
This is equivalent to QVariant(bool).toString()
Definition: mythlogging.h:86
MBASE_PUBLIC int syslogGetFacility(const QString &facility)
Map a syslog facility name back to the enumerated value.
Definition: logging.cpp:741
MBASE_PUBLIC void resetLogging(void)
Intended for use only by the test harness.
Definition: logging.cpp:111
MBASE_PUBLIC uint64_t verboseMask
Definition: logging.cpp:97
MBASE_PUBLIC ComponentLogLevelMap componentLogLevel
Definition: logging.cpp:99
MBASE_PUBLIC void logPropagateCalc(void)
Generate the logPropagateArgs global with the latest logging level, mask, etc to propagate to all of ...
Definition: logging.cpp:581
static bool VERBOSE_LEVEL_NONE()
Definition: mythlogging.h:28
MBASE_PUBLIC void logStop(void)
Entry point for stopping logging for an application.
Definition: logging.cpp:685
MBASE_PUBLIC QString logPropagateArgs
Definition: logging.cpp:82
QMap< uint64_t, LogLevel_t > ComponentLogLevelMap
Definition: verbosedefs.h:224