Go to the documentation of this file. 1 #ifndef LOGGINGSERVER_H_
2 #define LOGGINGSERVER_H_
4 #include <QMutexLocker>
5 #include <QSocketNotifier>
8 #include <QElapsedTimer>
14 #include "mythconfig.h"
19 #define LOGLINE_MAX (2048-120)
39 virtual void reopen(
void) = 0;
55 void reopen(
void)
override;
70 explicit SyslogLogger(
bool open);
71 ~SyslogLogger()
override;
74 void reopen(
void)
override { }
75 static SyslogLogger *create(QMutex *mutex,
bool open =
true);
77 bool m_opened {
false};
81 #if CONFIG_SYSTEMD_JOURNAL
88 ~JournalLogger()
override;
91 void reopen(
void)
override { };
92 static JournalLogger *create(QMutex *mutex);
141 void run(
void)
override;
158 class QWaitCondition;
159 #define MAX_QUEUE_LEN 1000
174 void run(
void)
override;
bool logqmsg(MSqlQuery &query, LoggingItem *item)
Actually insert a log message from the queue into the database.
QSqlQuery wrapper that fetches a DB connection from the connection pool.
QElapsedTimer m_errorLoggingTime
Elapsed time since DB error logging was last done.
void reopen(void) override
Reopen the log file to facilitate log rolling.
bool m_opened
true when the logfile is opened
~DBLoggerThread() override
DBLoggerThread deconstructor.
QList< LogMessage * > LogMessageList
Base class for the various logging mechanisms.
static DatabaseLogger * create(const QString &table, QMutex *mutex)
DBLoggerThread * m_thread
The database queue handling thread.
bool logmsg(LoggingItem *item) override
Process a log message, writing to the logfile.
static bool tableExists(const QString &table)
Checks whether table exists and is ready for writing.
bool logmsg(LoggingItem *item) override
Process a log message, queuing it for logging to the database.
~LoggerBase() override
LoggerBase Deconstructor.
DBLoggerThread(DatabaseLogger *logger)
DBLoggerThread constructor.
bool m_aborted
Flag to abort the thread.
void stopDatabaseAccess(void) override
Stop logging to the database and wait for the thread to stop.
The logging items that are generated by LOG() and are sent to the console.
bool isDatabaseReady(void)
Check if the database is ready for use.
MBASE_PUBLIC void logForwardStop(void)
bool m_loggingTableExists
The desired logging table exists.
QString m_query
The database query to insert log messages.
The logging thread that forwards received messages to the consuming loggers via ZeroMQ.
static const int kMinDisabledTime
Minimum time to disable DB logging (in ms)
~LogForwardThread() override
LogForwardThread destructor.
void stop(void)
Tell the thread to stop by setting the m_aborted flag.
static void handleSigHup(void)
SIGHUP handler - reopen all open logfiles for logrollers.
bool m_opened
The database is opened.
Thread that manages the queueing of logging inserts for the database.
void run(void) override
Run the log forwarding thread.
QString m_handle
semi-opaque handle for identifying instance
DatabaseLogger(const char *table)
DatabaseLogger constructor.
LoggerBase(const char *string)
LoggerBase Constructor.
~DatabaseLogger() override
DatabaseLogger deconstructor.
DBLoggerThread & operator=(const DBLoggerThread &)=delete
int m_fd
contains the file descriptor for the logfile
LogForwardThread()
LogForwardThread constructor.
volatile bool m_aborted
Used during shutdown to indicate that the thread should stop ASAP.
MBASE_PUBLIC void logForwardMessage(const QList< QByteArray > &msg)
Database logger - logs to the MythTV database.
QElapsedTimer m_disabledTime
Elapsed time since the DB logging was disabled.
File-based logger - used for logfiles and console.
void stop(void)
Stop the thread by setting the abort flag.
void prepare(MSqlQuery &query)
Prepare the database query for use, and bind constant values to it.
~FileLogger() override
FileLogger deconstructor - close the logfile.
bool enqueue(LoggingItem *item)
Enqueues a LoggingItem onto the queue for the thread to consume.
static void logger(cdio_log_level_t level, const char *message)
This is a wrapper around QThread that does several additional things.
DatabaseLogger * m_logger
The associated logger instance.
QMutex m_queueMutex
Mutex for protecting the queue.
virtual bool logmsg(LoggingItem *item)=0
Process a log message for the logger instance.
virtual void reopen(void)=0
Reopen the log file to facilitate log rolling.
FileLogger(const char *filename)
FileLogger constructor.
void incomingSigHup(void)
void reopen(void) override
Reopen the logfile after a SIGHUP.
friend void logSigHup(void)
static FileLogger * create(const QString &filename, QMutex *mutex)
bool queueFull(void)
Indicates when the queue is full.
QList< QByteArray > LogMessage
MBASE_PUBLIC bool logForwardStart(void)
MSqlQuery query(MSqlQuery::InitCon())
QQueue< LoggingItem * > * m_queue
Queue of LoggingItems to insert.
static void forwardMessage(LogMessage *msg)
void run(void) override
Start the thread.
QWaitCondition * m_wait
Wait condition used for waiting for the queue to not be full.
virtual void stopDatabaseAccess(void)
Stop logging to the database.