QtCraft API C++ classes QML types Handbook

QcMessageLog Namespace

The log file of a program (decision E-834): a Qt message handler that writes every message that passes the logging rules to a QcLogWriter and then hands it on to the handler installed before (the console). More...

Header: #include <common/diagnostics/QcMessageLog.h>

Classes

struct Config
struct LineTime
struct Recent
struct RecentLine

Functions

QByteArray formatLine(QtMsgType type, const char *category, const QString &message, const QcMessageLog::LineTime &time, const QString &thread)
QcStatus install(const QcMessageLog::Config &config)
void installWithoutFile()
quint64 latestSequence()
void note(const char *category, const QString &text)
QString path()
QcMessageLog::Recent recent(int minimumSeverity, qsizetype count, quint64 after = 0, const QSet<QString> &categories = {})
int severity(QtMsgType type)
void uninstall()

Detailed Description

Each line carries the absolute time and the seconds since the start; warnings and worse land at once (the file is unbuffered), a fatal message also becomes the reason of the crash report. Thread-safe: messages from any thread are written whole under one mutex; a message the writer itself causes goes only to the previous handler.

Classes

class Config

The log file install() writes. More...

class LineTime

When a line was written: the local time and the milliseconds since the log started. More...

class Recent

What recent() found: the lines, and the sequence of the newest line kept when it looked (read under the same lock, so a caller that asks again after it gets every later line exactly once). More...

class RecentLine

One of the latest lines. More...

Function Documentation

QByteArray QcMessageLog::formatLine(QtMsgType type, const char *category, const QString &message, const QcMessageLog::LineTime &time, const QString &thread)

Returns one line of the file for message of type in category, written at time on thread: "<date time> +<seconds> <D|I|W|C|F> <category> [<thread>] <message>".

QcStatus QcMessageLog::install(const QcMessageLog::Config &config)

Installs the handler with the file of config (once; a second call replaces the file). Returns an error that says why the file cannot be written; then nothing is installed.

void QcMessageLog::installWithoutFile()

Installs only the handler, without a file: a fatal message still becomes the reason of the crash report. install() later adds the file.

quint64 QcMessageLog::latestSequence()

Returns the sequence of the newest line kept; 0 before the first.

void QcMessageLog::note(const char *category, const QString &text)

Writes text as an info line of category to the file only, not on to the console (lines a program prints to standard output itself).

QString QcMessageLog::path()

Returns the file written now; empty when none.

QcMessageLog::Recent QcMessageLog::recent(int minimumSeverity, qsizetype count, quint64 after = 0, const QSet<QString> &categories = {})

Returns the newest lines of at least minimumSeverity with a sequence above after, oldest first, at most count; with categories only lines of those categories.

int QcMessageLog::severity(QtMsgType type)

Returns the severity of type, in the order debug < info < warning < critical < fatal (0 to 4).

void QcMessageLog::uninstall()

Restores the previous handler and closes the file; safe without install().