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