MythTV
master
|
The logging thread that consumes the logging queue and dispatches each LoggingItem. More...
#include <libmythbase/logging.h>
Public Member Functions | |
LoggerThread (QString filename, bool progress, bool quiet, int facility) | |
LoggerThread constructor. More... | |
~LoggerThread () override | |
LoggerThread destructor. Triggers the deletion of all loggers. More... | |
void | run (void) override |
Run the logging thread. More... | |
void | stop (void) |
Stop the thread by setting the abort flag after waiting a second for the queue to be flushed. More... | |
bool | flush (int timeoutMS=200000) |
Wait for the queue to be flushed (up to a timeout) More... | |
void | fillItem (LoggingItem *item) |
Public Member Functions inherited from MThread | |
MThread (const QString &objectName) | |
Standard constructor. More... | |
MThread (const QString &objectName, QRunnable *runnable) | |
Use this constructor if you want the default run() method to run the QRunnable's run() method instead of entering the Qt event loop. More... | |
virtual | ~MThread () |
MThread (const MThread &)=delete | |
MThread & | operator= (const MThread &)=delete |
void | RunProlog (void) |
Sets up a thread, call this if you reimplement run(). More... | |
void | RunEpilog (void) |
Cleans up a thread's resources, call this if you reimplement run(). More... | |
QThread * | qthread (void) |
Returns the thread, this will always return the same pointer no matter how often you restart the thread. More... | |
void | setObjectName (const QString &name) |
QString | objectName (void) const |
void | setPriority (QThread::Priority priority) |
QThread::Priority | priority (void) const |
bool | isFinished (void) const |
bool | isRunning (void) const |
void | setStackSize (uint stackSize) |
uint | stackSize (void) const |
void | exit (int retcode=0) |
Use this to exit from the thread if you are using a Qt event loop. More... | |
void | start (QThread::Priority p=QThread::InheritPriority) |
Tell MThread to start running the thread in the near future. More... | |
void | terminate (void) |
Kill a thread unsafely. More... | |
void | quit (void) |
calls exit(0) More... | |
bool | wait (std::chrono::milliseconds time=std::chrono::milliseconds::max()) |
Wait for the MThread to exit, with a maximum timeout. More... | |
Static Public Member Functions | |
static void | handleItem (LoggingItem *item) |
Handles each LoggingItem. More... | |
Static Public Member Functions inherited from MThread | |
static void | ThreadSetup (const QString &name) |
This is to be called on startup in those few threads that haven't been ported to MThread. More... | |
static void | ThreadCleanup (void) |
This is to be called on exit in those few threads that haven't been ported to MThread. More... | |
static void | Cleanup (void) |
This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total for all the threads to exit. More... | |
static void | GetAllThreadNames (QStringList &list) |
static void | GetAllRunningThreadNames (QStringList &list) |
Protected Member Functions | |
bool | logConsole (LoggingItem *item) const |
Process a log message, writing to the console. More... | |
Protected Member Functions inherited from MThread | |
int | exec (void) |
Enters the qt event loop. call exit or quit to exit thread. More... | |
Private Member Functions | |
Q_DISABLE_COPY (LoggerThread) | |
Private Attributes | |
QWaitCondition * | m_waitNotEmpty {nullptr} |
Condition variable for waiting for the queue to not be empty Protected by logQueueMutex. More... | |
QWaitCondition * | m_waitEmpty {nullptr} |
Condition variable for waiting for the queue to be empty Protected by logQueueMutex. More... | |
bool | m_aborted {false} |
Flag to abort the thread. More... | |
QString | m_filename |
Filename of debug logfile. More... | |
bool | m_progress |
show only LOG_ERR and more important (console only) More... | |
bool | m_quiet |
silence the console (console only) More... | |
QString | m_appname {QCoreApplication::applicationName()} |
Cached application name. More... | |
int | m_facility |
Cached syslog facility (or -1 to disable) More... | |
pid_t | m_pid |
Cached pid value. More... | |
Friends | |
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. More... | |
Additional Inherited Members | |
Static Protected Member Functions inherited from MThread | |
static void | setTerminationEnabled (bool enabled=true) |
static void | usleep (std::chrono::microseconds time) |
template<typename R , typename P > | |
static std::enable_if_t< std::chrono::treat_as_floating_point< R >::value, void > | usleep (std::chrono::duration< R, P > time) |
Protected Attributes inherited from MThread | |
MThreadInternal * | m_thread {nullptr} |
QRunnable * | m_runnable {nullptr} |
bool | m_prologExecuted {true} |
bool | m_epilogExecuted {true} |
The logging thread that consumes the logging queue and dispatches each LoggingItem.
LoggerThread constructor.
Enables debugging of thread registration and deregistration if the VERBOSE_THREADS environment variable is set.
Definition at line 218 of file logging.cpp.
|
override |
LoggerThread destructor. Triggers the deletion of all loggers.
Definition at line 242 of file logging.cpp.
|
overridevirtual |
Run the logging thread.
This thread reads from the logging queue, and handles distributing the LoggingItems to each logger instance. The thread will not exit until the logging queue is emptied completely, ensuring that all logging is flushed.
Reimplemented from MThread.
Definition at line 256 of file logging.cpp.
void LoggerThread::stop | ( | void | ) |
Stop the thread by setting the abort flag after waiting a second for the queue to be flushed.
Definition at line 464 of file logging.cpp.
Referenced by logStop(), and ~LoggerThread().
bool LoggerThread::flush | ( | int | timeoutMS = 200000 | ) |
Wait for the queue to be flushed (up to a timeout)
timeoutMS | The number of ms to wait for the queue to flush |
Definition at line 476 of file logging.cpp.
Referenced by LogPrintLine(), and stop().
|
static |
Handles each LoggingItem.
There is a special case for thread registration and deregistration which are also included in the logging queue to keep the thread names in sync with the log messages.
item | The LoggingItem to be handled |
Definition at line 312 of file logging.cpp.
Referenced by LogPrintLine(), and run().
void LoggerThread::fillItem | ( | LoggingItem * | item | ) |
Definition at line 490 of file logging.cpp.
Referenced by run().
|
private |
|
protected |
Process a log message, writing to the console.
item | LoggingItem containing the log message to process |
Definition at line 364 of file logging.cpp.
Referenced by LogPrintLine(), and run().
|
friend |
Format and send a log message into the queue.
This is called from the LOG() macro. The intention is minimal blocking of the caller.
mask | Verbosity mask of the message (VB_*) |
level | Log level of this message (LOG_* - matching syslog levels) |
file | Filename of source code logging the message |
line | Line number within the source of log message source |
function | Function name of the log message source |
message | log message |
Definition at line 528 of file logging.cpp.
|
private |
|
private |
Condition variable for waiting for the queue to be empty Protected by logQueueMutex.
Definition at line 164 of file logging.h.
Referenced by flush(), run(), and ~LoggerThread().
|
private |
|
private |
show only LOG_ERR and more important (console only)
Definition at line 171 of file logging.h.
Referenced by logConsole().
|
private |
silence the console (console only)
Definition at line 172 of file logging.h.
Referenced by logConsole().
|
private |
|
private |
Cached syslog facility (or -1 to disable)
Definition at line 175 of file logging.h.
Referenced by fillItem().
|
private |