MythTV  master
loggingserver.h
Go to the documentation of this file.
1 #ifndef LOGGINGSERVER_H_
2 #define LOGGINGSERVER_H_
3 
4 #include <QMutexLocker>
5 #include <QSocketNotifier>
6 #include <QMutex>
7 #include <QQueue>
8 #include <QElapsedTimer>
9 
10 #include <cstdint>
11 #include <ctime>
12 #include <fstream>
13 #include <unistd.h>
14 
15 #include "mythconfig.h"
16 #include "mythbaseexp.h" // MBASE_PUBLIC , etc.
17 #include "verbosedefs.h"
18 #include "mthread.h"
19 
20 class QString;
21 class MSqlQuery;
22 class LoggingItem;
23 
26 {
27  public:
29  explicit LoggerBase(const char *string);
31  virtual ~LoggerBase();
34  virtual bool logmsg(LoggingItem *item) = 0;
36  virtual void reopen(void) = 0;
37  protected:
38  QString m_handle;
39 };
40 
42 class FileLogger : public LoggerBase
43 {
44  public:
45  explicit FileLogger(const char *filename);
46  ~FileLogger() override;
47  bool logmsg(LoggingItem *item) override; // LoggerBase
48  void reopen(void) override; // LoggerBase
49  static FileLogger *create(const QString& filename, QMutex *mutex);
50  private:
51  std::ofstream m_ofstream;
52 };
53 
54 #ifndef _WIN32
55 class SyslogLogger : public LoggerBase
57 {
58  public:
59  explicit SyslogLogger(bool open);
60  ~SyslogLogger() override;
61  bool logmsg(LoggingItem *item) override; // LoggerBase
63  void reopen(void) override { } // LoggerBase
64  static SyslogLogger *create(QMutex *mutex, bool open = true);
65  private:
66  bool m_opened {false};
67 };
68 #endif
69 
70 #if CONFIG_SYSTEMD_JOURNAL
71 class JournalLogger : public LoggerBase
72 {
73  public:
74  JournalLogger();
75  ~JournalLogger() override;
76  bool logmsg(LoggingItem *item) override; // LoggerBase
78  void reopen(void) override { }; // LoggerBase
79  static JournalLogger *create(QMutex *mutex);
80 };
81 #endif
82 
83 using LoggingItemList = QList<LoggingItem *>;
84 
87 class LogForwardThread : public QObject, public MThread
88 {
89  Q_OBJECT
90 
91  friend void logSigHup(void);
92  public:
94  ~LogForwardThread() override;
95  void run(void) override; // MThread
96  void stop(void);
97  private:
98  bool m_aborted {false};
99 
100  static void forwardMessage(LoggingItem *item);
101  signals:
102  void incomingSigHup(void);
103  protected slots:
104  static void handleSigHup(void);
105 };
106 
107 MBASE_PUBLIC bool logForwardStart(void);
108 MBASE_PUBLIC void logForwardStop(void);
110 
111 
112 #ifndef _WIN32
113 MBASE_PUBLIC void logSigHup(void);
114 #endif
115 
116 #endif
117 
118 /*
119  * vim:ts=4:sw=4:ai:et:si:sts=4
120  */
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:127
LoggerBase
Base class for the various logging mechanisms.
Definition: loggingserver.h:25
logForwardMessage
MBASE_PUBLIC void logForwardMessage(LoggingItem *item)
Definition: loggingserver.cpp:489
mythbaseexp.h
FileLogger::logmsg
bool logmsg(LoggingItem *item) override
Process a log message, writing to the logfile.
Definition: loggingserver.cpp:159
verbosedefs.h
LoggerBase::~LoggerBase
virtual ~LoggerBase()
LoggerBase Deconstructor.
Definition: loggingserver.cpp:99
LogForwardThread::m_aborted
bool m_aborted
Flag to abort the thread.
Definition: loggingserver.h:98
LoggingItem
The logging items that are generated by LOG() and are sent to the console.
Definition: logging.h:54
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
logForwardStop
MBASE_PUBLIC void logForwardStop(void)
Definition: loggingserver.cpp:477
LogForwardThread
The logging thread that forwards received messages to the consuming loggers via ZeroMQ.
Definition: loggingserver.h:87
LogForwardThread::~LogForwardThread
~LogForwardThread() override
LogForwardThread destructor.
Definition: loggingserver.cpp:308
LogForwardThread::handleSigHup
static void handleSigHup(void)
SIGHUP handler - reopen all open logfiles for logrollers.
Definition: loggingserver.cpp:380
LogForwardThread::run
void run(void) override
Run the log forwarding thread.
Definition: loggingserver.cpp:317
LoggerBase::m_handle
QString m_handle
semi-opaque handle for identifying instance
Definition: loggingserver.h:38
LoggerBase::LoggerBase
LoggerBase(const char *string)
LoggerBase Constructor.
Definition: loggingserver.cpp:89
FileLogger::m_ofstream
std::ofstream m_ofstream
Output file stream for the log file.
Definition: loggingserver.h:51
LogForwardThread::LogForwardThread
LogForwardThread()
LogForwardThread constructor.
Definition: loggingserver.cpp:301
LogForwardThread::forwardMessage
static void forwardMessage(LoggingItem *item)
Definition: loggingserver.cpp:395
FileLogger
File-based logger - used for logfiles and console.
Definition: loggingserver.h:42
LogForwardThread::stop
void stop(void)
Stop the thread by setting the abort flag.
Definition: loggingserver.cpp:463
FileLogger::~FileLogger
~FileLogger() override
FileLogger deconstructor - close the logfile.
Definition: loggingserver.cpp:118
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
mthread.h
LoggingItemList
QList< LoggingItem * > LoggingItemList
Definition: loggingserver.h:83
LoggerBase::logmsg
virtual bool logmsg(LoggingItem *item)=0
Process a log message for the logger instance.
LoggerBase::reopen
virtual void reopen(void)=0
Reopen the log file to facilitate log rolling.
FileLogger::FileLogger
FileLogger(const char *filename)
FileLogger constructor.
Definition: loggingserver.cpp:108
LogForwardThread::incomingSigHup
void incomingSigHup(void)
FileLogger::reopen
void reopen(void) override
Reopen the logfile after a SIGHUP.
Definition: loggingserver.cpp:149
LogForwardThread::logSigHup
friend void logSigHup(void)
FileLogger::create
static FileLogger * create(const QString &filename, QMutex *mutex)
Definition: loggingserver.cpp:128
build_compdb.filename
filename
Definition: build_compdb.py:21
logForwardStart
MBASE_PUBLIC bool logForwardStart(void)
Definition: loggingserver.cpp:468