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