QXmppLogger Class
The QXmppLogger class represents a sink for logging messages. More...
| Header: | #include <QXmppLogger.h> |
| Inherits: | QObject |
- List of all members, including inherited members
- Deprecated members
- QXmppLogger is part of Core classes.
Public Types
| enum | ColorMode { ColorOff, ColorOn, ColorAuto } |
| enum | LoggingType { NoLogging, FileLogging, StdoutLogging, SignalLogging } |
| enum | MessageType { NoMessage, DebugMessage, InformationMessage, WarningMessage, ReceivedMessage, …, AnyMessage } |
| flags | MessageTypes |
(since QXmpp 1.17) enum class | OutputMode { Auto, Raw, Pretty } |
Properties
|
|
Public Functions
| QXmppLogger(QObject *parent = nullptr) | |
(since QXmpp 1.16) QXmppLogger::ColorMode | colorMode() const |
(since QXmpp 1.17) std::optional<qsizetype> | elideLogMessagesAbove() const |
(since QXmpp 1.17) std::optional<qsizetype> | elideXmlTextAbove() const |
(since QXmpp 1.17) void | enableEliding(bool enable = true) |
(since QXmpp 1.17) bool | filterStreamManagementAcks() const |
| QString | logFilePath() |
| QXmppLogger::LoggingType | loggingType() |
| QXmppLogger::MessageTypes | messageTypes() |
(since QXmpp 1.17) QXmppLogger::OutputMode | outputMode() const |
(since QXmpp 1.16) void | setColorMode(QXmppLogger::ColorMode mode) |
(since QXmpp 1.17) void | setElideLogMessagesAbove(std::optional<qsizetype> length) |
(since QXmpp 1.17) void | setElideXmlTextAbove(std::optional<qsizetype> length) |
(since QXmpp 1.17) void | setFilterStreamManagementAcks(bool enable) |
| void | setLogFilePath(const QString &path) |
| void | setLoggingType(QXmppLogger::LoggingType type) |
| void | setMessageTypes(QXmppLogger::MessageTypes types) |
(since QXmpp 1.17) void | setOutputMode(QXmppLogger::OutputMode mode) |
Public Slots
| void | log(QXmppLogger::MessageType type, const QString &text) |
| void | reopen() |
| virtual void | setGauge(const QString &gauge, double value) |
| virtual void | updateCounter(const QString &counter, qint64 amount) |
Signals
| void | colorModeChanged() |
(since QXmpp 1.7) void | logFilePathChanged() |
(since QXmpp 1.7) void | loggingTypeChanged() |
| void | message(QXmppLogger::MessageType type, const QString &text) |
(since QXmpp 1.7) void | messageTypesChanged() |
| void | outputModeChanged() |
Static Public Members
(since QXmpp 1.17) const qsizetype | DefaultElideLogMessagesAbove |
(since QXmpp 1.17) const qsizetype | DefaultElideXmlTextAbove |
| QXmppLogger * | getLogger() |
Detailed Description
Member Type Documentation
enum QXmppLogger::ColorMode
Controls ANSI color output for pretty-printed XML.
| Constant | Value | Description |
|---|---|---|
QXmppLogger::ColorOff | 0 | Never emit color escapes |
QXmppLogger::ColorOn | 1 | Always emit color escapes |
QXmppLogger::ColorAuto | 2 | Emit colors when loggingType is StdoutLogging and stdout is a TTY |
enum QXmppLogger::LoggingType
This enum describes how log message are handled.
| Constant | Value | Description |
|---|---|---|
QXmppLogger::NoLogging | 0 | Log messages are discarded. |
QXmppLogger::FileLogging | 1 | Log messages are written to a file. |
QXmppLogger::StdoutLogging | 2 | Log messages are written to the standard output. |
QXmppLogger::SignalLogging | 4 | Log messages are emitted as a signal. |
enum QXmppLogger::MessageType
flags QXmppLogger::MessageTypes
This enum describes a type of log message.
| Constant | Value | Description |
|---|---|---|
QXmppLogger::NoMessage | 0 | No message type. |
QXmppLogger::DebugMessage | 1 | Debugging message. |
QXmppLogger::InformationMessage | 2 | Informational message. |
QXmppLogger::WarningMessage | 4 | Warning message. |
QXmppLogger::ReceivedMessage | 8 | Message received from server. |
QXmppLogger::SentMessage | 16 | Message sent to server. |
QXmppLogger::AnyMessage | 31 | Any message type. |
The MessageTypes type is a typedef for QFlags<MessageType>. It stores an OR combination of MessageType values.
[since QXmpp 1.17] enum class QXmppLogger::OutputMode
This enum describes how logged Sent/Received XML is formatted.
| Constant | Value | Description |
|---|---|---|
QXmppLogger::OutputMode::Auto | 0 | Format for humans if loggingType is StdoutLogging, pass XML through unchanged otherwise. This is the default. |
QXmppLogger::OutputMode::Raw | 1 | Pass logged XML through unchanged, so it can be reparsed. |
QXmppLogger::OutputMode::Pretty | 2 | Pretty-print XML, colorize it according to colorMode and elide overly long messages. |
This enum was introduced in QXmpp 1.17.
Property Documentation
colorMode : ColorMode
How to decide whether to use ANSI color escapes for pretty XML
Access functions:
| QXmppLogger::ColorMode | colorMode() const |
| void | setColorMode(QXmppLogger::ColorMode mode) |
Notifier signal:
| void | colorModeChanged() |
logFilePath : QString
The path to which logging messages should be written
Access functions:
| QString | logFilePath() |
| void | setLogFilePath(const QString &path) |
Notifier signal:
| void | logFilePathChanged() |
loggingType : LoggingType
The handler for logging messages
Access functions:
| QXmppLogger::LoggingType | loggingType() |
| void | setLoggingType(QXmppLogger::LoggingType type) |
Notifier signal:
| void | loggingTypeChanged() |
messageTypes : MessageTypes
The types of messages to log
Access functions:
| QXmppLogger::MessageTypes | messageTypes() |
| void | setMessageTypes(QXmppLogger::MessageTypes types) |
Notifier signal:
| void | messageTypesChanged() |
outputMode : OutputMode
How logged Sent/Received XML is formatted
Access functions:
| QXmppLogger::OutputMode | outputMode() const |
| void | setOutputMode(QXmppLogger::OutputMode mode) |
Notifier signal:
| void | outputModeChanged() |
Member Function Documentation
QXmppLogger::QXmppLogger(QObject *parent = nullptr)
Constructs a new QXmppLogger with parent.
[since QXmpp 1.16] QXmppLogger::ColorMode QXmppLogger::colorMode() const
Returns the current ANSI color mode for pretty-printed XML.
Note: Getter function for property colorMode.
This function was introduced in QXmpp 1.16.
See also setColorMode().
[since QXmpp 1.17] std::optional<qsizetype> QXmppLogger::elideLogMessagesAbove() const
Returns the maximum length of a logged message, or std::nullopt if messages are never elided.
This function was introduced in QXmpp 1.17.
See also setElideLogMessagesAbove().
[since QXmpp 1.17] std::optional<qsizetype> QXmppLogger::elideXmlTextAbove() const
Returns the maximum length of an XML text node in logged stanzas, or std::nullopt if text nodes are never elided.
This function was introduced in QXmpp 1.17.
See also setElideXmlTextAbove().
[since QXmpp 1.17] void QXmppLogger::enableEliding(bool enable = true)
Enables (enable) eliding of overly long Sent/Received messages using default limits.
Equivalent to calling setElideXmlTextAbove(DefaultElideXmlTextAbove) and setElideLogMessagesAbove(DefaultElideLogMessagesAbove), or, if disabling, setting both to std::nullopt. Use those setters directly to pick your own limits.
Eliding is enabled by default, so this is mainly useful as enableEliding(false) to log full stanzas in OutputMode::Pretty. It has no effect in OutputMode::Raw.
This function was introduced in QXmpp 1.17.
See also setElideXmlTextAbove() and setElideLogMessagesAbove().
[since QXmpp 1.17] bool QXmppLogger::filterStreamManagementAcks() const
Returns whether XEP-0198: Stream Management ack stanzas (<r/> and <a/>) are filtered out of Sent/Received logging.
These tiny stanzas are exchanged very frequently and otherwise flood the log. Enabled by default.
This function was introduced in QXmpp 1.17.
See also setFilterStreamManagementAcks().
[static] QXmppLogger *QXmppLogger::getLogger()
Returns the default logger.
[slot] void QXmppLogger::log(QXmppLogger::MessageType type, const QString &text)
Add a logging message.
type and text.
QString QXmppLogger::logFilePath()
Returns the path to which logging messages should be written.
Note: Getter function for property logFilePath.
See also setLogFilePath() and loggingType().
[signal, since QXmpp 1.7] void QXmppLogger::logFilePathChanged()
Emitted when the log file path has been changed.
Note: Notifier signal for property logFilePath.
This function was introduced in QXmpp 1.7.
QXmppLogger::LoggingType QXmppLogger::loggingType()
Returns the handler for logging messages.
Note: Getter function for property loggingType.
See also setLoggingType().
[signal, since QXmpp 1.7] void QXmppLogger::loggingTypeChanged()
Emitted when the logging type has been changed.
Note: Notifier signal for property loggingType.
This function was introduced in QXmpp 1.7.
[signal] void QXmppLogger::message(QXmppLogger::MessageType type, const QString &text)
This signal is emitted whenever a log message is received.
type and text.
QXmppLogger::MessageTypes QXmppLogger::messageTypes()
Returns the types of messages to log.
Note: Getter function for property messageTypes.
See also setMessageTypes().
[signal, since QXmpp 1.7] void QXmppLogger::messageTypesChanged()
Emitted when the message types have been changed.
Note: Notifier signal for property messageTypes.
This function was introduced in QXmpp 1.7.
[since QXmpp 1.17] QXmppLogger::OutputMode QXmppLogger::outputMode() const
Returns how logged Sent/Received XML is formatted. See OutputMode.
Note: Getter function for property outputMode.
This function was introduced in QXmpp 1.17.
See also setOutputMode().
[slot] void QXmppLogger::reopen()
If logging to a file, causes the file to be re-opened.
[since QXmpp 1.16] void QXmppLogger::setColorMode(QXmppLogger::ColorMode mode)
Sets the ANSI color mode for pretty-printed XML. See ColorMode.
Note: Setter function for property colorMode.
This function was introduced in QXmpp 1.16.
See also colorMode().
[since QXmpp 1.17] void QXmppLogger::setElideLogMessagesAbove(std::optional<qsizetype> length)
Sets the maximum length of a logged message.
Messages longer than length are elided in the middle, so the beginning and the end stay visible. Unlike setElideXmlTextAbove() this also shortens stanzas that are large because of the sheer number of elements they contain, as well as payloads that are not valid XML.
Only applies to Sent/Received messages. Pass std::nullopt to never elide messages. Only has an effect in OutputMode::Pretty.
This function was introduced in QXmpp 1.17.
See also elideLogMessagesAbove(), setElideXmlTextAbove(), and enableEliding().
[since QXmpp 1.17] void QXmppLogger::setElideXmlTextAbove(std::optional<qsizetype> length)
Sets the maximum length of an XML text node in logged stanzas.
Text nodes longer than length are elided in the middle, so the beginning and the end of the content stay visible while the XML structure around them is preserved. This is useful for large base64 payloads (avatars, file previews, encrypted content).
Only applies to Sent/Received messages. Pass std::nullopt to never elide text nodes. Only has an effect in OutputMode::Pretty.
This function was introduced in QXmpp 1.17.
See also elideXmlTextAbove(), setElideLogMessagesAbove(), and enableEliding().
[since QXmpp 1.17] void QXmppLogger::setFilterStreamManagementAcks(bool enable)
Sets whether XEP-0198: Stream Management ack stanzas (<r/> and <a/>) are filtered out of Sent/Received logging (enable).
This function was introduced in QXmpp 1.17.
See also filterStreamManagementAcks().
[virtual slot] void QXmppLogger::setGauge(const QString &gauge, double value)
Sets the given gauge to value.
NOTE: the base implementation does nothing.
void QXmppLogger::setLogFilePath(const QString &path)
Sets the path to which logging messages should be written to path.
Note: Setter function for property logFilePath.
See also logFilePath() and setLoggingType().
void QXmppLogger::setLoggingType(QXmppLogger::LoggingType type)
Sets the handler for logging messages.
type.
Note: Setter function for property loggingType.
See also loggingType().
void QXmppLogger::setMessageTypes(QXmppLogger::MessageTypes types)
Sets the types of messages to log.
Note: Setter function for property messageTypes.
See also messageTypes().
[since QXmpp 1.17] void QXmppLogger::setOutputMode(QXmppLogger::OutputMode mode)
Sets how logged Sent/Received XML is formatted (mode). See OutputMode.
Formatting for humans is only enabled by default for StdoutLogging. Set OutputMode::Pretty to format the output of the other logging types too, e.g. when logging via signals and printing the messages yourself.
Note: Setter function for property outputMode.
This function was introduced in QXmpp 1.17.
See also outputMode().
[virtual slot] void QXmppLogger::updateCounter(const QString &counter, qint64 amount)
Updates the given counter by amount.
NOTE: the base implementation does nothing.
Member Variable Documentation
[since QXmpp 1.17] const qsizetype QXmppLogger::DefaultElideLogMessagesAbove
Default maximum length of a logged message in OutputMode::Pretty.
This variable was introduced in QXmpp 1.17.
[since QXmpp 1.17] const qsizetype QXmppLogger::DefaultElideXmlTextAbove
Default maximum length of an XML text node in OutputMode::Pretty.
This variable was introduced in QXmpp 1.17.