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 <fstream>
12#include <unistd.h>
13
14#include "mythconfig.h"
15#include "mythbaseexp.h" // MBASE_PUBLIC , etc.
16#include "verbosedefs.h"
17#include "mthread.h"
18
19class QString;
20class MSqlQuery;
21class LoggingItem;
22
25{
26 public:
28 explicit LoggerBase(const char *string);
30 virtual ~LoggerBase();
33 virtual bool logmsg(LoggingItem *item) = 0;
35 virtual void reopen(void) = 0;
36 protected:
37 QString m_handle;
38};
39
41class FileLogger : public LoggerBase
42{
43 public:
44 explicit FileLogger(const char *filename);
45 ~FileLogger() override;
46 bool logmsg(LoggingItem *item) override; // LoggerBase
47 void reopen(void) override; // LoggerBase
48 static FileLogger *create(const QString& filename, QMutex *mutex);
49 private:
50 std::ofstream m_ofstream;
51};
52
53#ifndef _WIN32
55class SyslogLogger : public LoggerBase
56{
57 public:
58 explicit SyslogLogger(bool open);
59 ~SyslogLogger() override;
60 bool logmsg(LoggingItem *item) override; // LoggerBase
62 void reopen(void) override { } // LoggerBase
63 static SyslogLogger *create(QMutex *mutex, bool open = true);
64 private:
65 bool m_opened {false};
66};
67#endif
68
69#if CONFIG_SYSTEMD_JOURNAL
70class JournalLogger : public LoggerBase
71{
72 public:
73 JournalLogger();
74 ~JournalLogger() override;
75 bool logmsg(LoggingItem *item) override; // LoggerBase
77 void reopen(void) override { }; // LoggerBase
78 static JournalLogger *create(QMutex *mutex);
79};
80#endif
81
82using LoggingItemList = QList<LoggingItem *>;
83
86class LogForwardThread : public QObject, public MThread
87{
88 Q_OBJECT
89
90 friend void logSigHup(void);
91 public:
93 ~LogForwardThread() override;
94 void run(void) override; // MThread
95 void stop(void);
96 private:
97 bool m_aborted {false};
98
99 static void forwardMessage(LoggingItem *item);
100 signals:
101 void incomingSigHup(void);
102 protected slots:
103 static void handleSigHup(void);
104};
105
109
110
111#ifndef _WIN32
112MBASE_PUBLIC void logSigHup(void);
113#endif
114
115#endif
116
117/*
118 * vim:ts=4:sw=4:ai:et:si:sts=4
119 */
File-based logger - used for logfiles and console.
Definition: loggingserver.h:42
static FileLogger * create(const QString &filename, QMutex *mutex)
std::ofstream m_ofstream
Output file stream for the log file.
Definition: loggingserver.h:50
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:87
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.
Definition: loggingserver.h:97
void incomingSigHup(void)
Base class for the various logging mechanisms.
Definition: loggingserver.h:25
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:37
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:55
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:82
MBASE_PUBLIC void logForwardMessage(LoggingItem *item)
MBASE_PUBLIC bool logForwardStart(void)
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15