8#include <QCoreApplication>
14#include "mythconfig.h"
26#if CONFIG_SYSTEMD_JOURNAL
27static constexpr int SYSTEMD_JOURNAL_FACILITY { -99 };
81 static
LoggingItem *
create(const
char *_file, const
char *_function,
int _line, LogLevel_t _level,
83 QString
getTimestamp(const
char *format = "yyyy-MM-dd HH:mm:ss") const;
84 QString
getTimestampUs(const
char *format = "yyyy-MM-dd HH:mm:ss") const;
141 LoggingItem(
const char *_file,
const char *_function,
153 const char *function, QString message);
157 void run(
void)
override;
159 bool flush(
int timeoutMS = 200000);
178 QString
m_appname {QCoreApplication::applicationName()};
The logging thread that consumes the logging queue and dispatches each LoggingItem.
void stop(void)
Stop the thread by setting the abort flag after waiting a second for the queue to be flushed.
LoggerThread(QString filename, bool progress, bool quiet, int facility, bool loglong)
LoggerThread constructor.
bool m_quiet
silence the console (console only)
friend 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.
bool m_progress
show only LOG_ERR and more important (console only)
QString m_appname
Cached application name.
int m_facility
Cached syslog facility (or -1 to disable)
Q_DISABLE_COPY(LoggerThread)
void run(void) override
Run the logging thread.
~LoggerThread() override
LoggerThread destructor. Triggers the deletion of all loggers.
QWaitCondition * m_waitEmpty
Condition variable for waiting for the queue to be empty Protected by logQueueMutex.
void fillItem(LoggingItem *item)
bool flush(int timeoutMS=200000)
Wait for the queue to be flushed (up to a timeout)
pid_t m_pid
Cached pid value.
bool logConsole(LoggingItem *item) const
Process a log message, writing to the console.
bool m_aborted
Flag to abort the thread.
QWaitCondition * m_waitNotEmpty
Condition variable for waiting for the queue to not be empty Protected by logQueueMutex.
bool m_loglong
use long log format (console only)
QString m_filename
Filename of debug logfile.
static void handleItem(LoggingItem *item)
Handles each LoggingItem.
The logging items that are generated by LOG() and are sent to the console.
void setEpochInt(const qlonglong val)
Q_DISABLE_COPY(LoggingItem)
friend 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.
char getLevelChar(void)
Get the message log level as a single character.
static LoggingItem * create(const char *_file, const char *_function, int _line, LogLevel_t _level, LoggingType _type)
Create a new LoggingItem.
void setEpoch(std::chrono::microseconds val)
void setTid(const qlonglong val)
std::chrono::microseconds epoch() const
void setFunction(const QString &val)
void setThreadName(const QString &val)
QString getTimestampUs(const char *format="yyyy-MM-dd HH:mm:ss") const
void setLine(const int val)
void setMessage(const QString &val)
void setAppName(const QString &val)
std::string toString()
Long format to string.
void setPid(const int val)
qlonglong epochInt() const
QString threadName() const
void setFacility(const int val)
void setLevel(const int val)
void setType(const int val)
QString getTimestamp(const char *format="yyyy-MM-dd HH:mm:ss") const
Convert numerical timestamp to a readable date and time.
void setFile(const QString &val)
int64_t getThreadTid(void)
Get the thread ID of the thread that produced the LoggingItem.
void setThreadTid(void)
Set the thread ID of the thread that produced the LoggingItem.
void setLogFile(const QString &val)
std::string toStringShort()
short console format
qulonglong threadId() const
std::chrono::microseconds m_epoch
void setThreadId(const qulonglong val)
QString getThreadName(void)
Get the name of the thread that produced the LoggingItem.
QSqlQuery wrapper that fetches a DB connection from the connection pool.
This is a wrapper around QThread that does several additional things.
General purpose reference counter.
void loggingDeregisterThread(void)
Deregister the current thread's name.
void loggingRegisterThread(const QString &name)
Register the current thread with the given name.