Home · Modules · Classes · Namespaces · Functions

QxtLogger Class Reference
[QxtCore module]

The QxtLogger class is an easy to use, easy to extend logging tool. More...

    #include <QxtLogger>

Inherits QObject.

Public Types

Public Functions

Public Slots

Signals

Static Public Members

Macros

Additional Inherited Members


Detailed Description

The QxtLogger class is an easy to use, easy to extend logging tool.

Overview

QxtLogger is an easy to use, easy to extend, thread-safe logging tool. It was designed to be used "out of the box".

    #include <QxtLogger>
    ...
    QxtLogger::getInstance()->debug("Hi!"); // without using the macro
    qxtLog->debug("Hi!"); // using the macro

Usage

QxtLogger is designed to work "out of the box". The Logger itself is a singleton object that manages all of the logging that is requested. It provides 8 methods to actually log content; they are listed from the most logically verbose to the most logically important:

These named members only have meaning to the person who uses them. For example, you could call qxtLog->trace() from many parts of a complicated, massively recursive function to trace it's output; use qxtLog->info() to log that an event such as "Logging has started" has happened; use qxtLog->fatal() when an unhandled exception is thrown. Or, you could use qxtLog->write() for everything.

Each of these members comes in two forms: the first takes up to ten QVariants (for moc compatibility), the second form takes a QList<QVariant>. Thus, you can invoke the info() member in the following ways:

    // Using the 10-param members.
    qxtLog->info(15);
    qxtLog->info("I am a test");
    qxtLog->info(QTime::currentTime(), "something happened", 3.14);

    // Now with QList<QVariant>
    qxtLog->info(QList<QVariant>() << "test" << 15 << QTime::currentTime());

The real power behind QxtLogger comes from telling it which log levels you actually want to see. Calling qxtLog->enableAllLogLevels() can give you a lot of data if you need it. But if you only want to see warnings and errors, qxtLog->setMinimumLogLevel(WarningLevel) might be more useful.

Extending

The functionality of QxtLogger can be extended by creating plugins derived from QxtLoggerEngine. Logger Engines are the little workers that actually take the raw data, format it, and spit it out into meaningful forms.

See also getInstance().


Member Type Documentation

enum QxtLogger::LogLevel
flags QxtLogger::LogLevels

The LogLevels type is a typedef for QFlags<LogLevel>. It stores an OR combination of LogLevel values.


Member Function Documentation

void QxtLogger::addLoggerEngine ( const QString & engineName, QxtLoggerEngine * engine )

Gives QxtLogger an already-instantiated QxtLoggerEngine to use. addLoggerEngine inserts a subclass of QxtLoggerEngine for QxtLogger to manage. QxtLogger takes ownership of the engine and will manage memory on its own.

    #include <QxtLogger>
    ...
    class MyLoggerEngine : public QxtLoggerEngine;
    ...
    qxtLog->addLoggerEngine("my engine", new MyLoggerEngine);

See also QxtLoggerEngine.

QStringList QxtLogger::allDisabledLoggerEngines () const

Retuns a QStringList containing the names of all loaded Engines that are currently disabled. Returns QStringList engine names.

QStringList QxtLogger::allEnabledLoggerEngines () const

Retuns a QStringList containing the names of all loaded Engines that are currently enabled. Returns QStringList engine names.

QStringList QxtLogger::allEnabledLoggerEngines ( LogLevel level ) const

Retuns a QStringList containing the names of all loaded Engines that have currently certain log level enabled. Returns QStringList engine names.

QStringList QxtLogger::allLoggerEngines () const

Retuns a QStringList containing the names of all loaded Engines being managed by QxtLogger. Returns QStringList engine names.

QxtLogStream QxtLogger::critical ()

Opens a stream to write a message to all Engines with the CriticalLevel set. The parameterless logging functions return a QxtLogStream for use similar to qDebug().

    qxtLog->critical() << "critical error message";

void QxtLogger::critical ( const QVariant & message, const QVariant & msg1 = QVariant(), const QVariant & msg2 = QVariant(), const QVariant & msg3 = QVariant(), const QVariant & msg4 = QVariant(), const QVariant & msg5 = QVariant(), const QVariant & msg6 = QVariant(), const QVariant & msg7 = QVariant(), const QVariant & msg8 = QVariant(), const QVariant & msg9 = QVariant() )   [slot]

Writes a message to all Engines with the CriticalLevel set. The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc currently only accepts functions with up to 10 parameters. They can take any value that QVariant can take as an argument.

void QxtLogger::critical ( const QList<QVariant> & args )   [slot]

Writes a message to all Engines with the CriticalLevel set. The 1-parameter logging messages can take any number of arguments in the form of a QList<QVariant>, or QList<QVariant>.

QxtLogStream QxtLogger::debug ()

Opens a stream to write a message to all Engines with the DebugLevel set. The parameterless logging functions return a QxtLogStream for use similar to qDebug().

    qxtLog->debug() << "debugging log message";

void QxtLogger::debug ( const QVariant & message, const QVariant & msg1 = QVariant(), const QVariant & msg2 = QVariant(), const QVariant & msg3 = QVariant(), const QVariant & msg4 = QVariant(), const QVariant & msg5 = QVariant(), const QVariant & msg6 = QVariant(), const QVariant & msg7 = QVariant(), const QVariant & msg8 = QVariant(), const QVariant & msg9 = QVariant() )   [slot]

Writes a message to all Engines with the DebugLevel set. The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc currently only accepts functions with up to 10 parameters. They can take any value that QVariant can take as an argument.

void QxtLogger::debug ( const QList<QVariant> & args )   [slot]

Writes a message to all Engines with the DebugLevel set. The 1-parameter logging messages can take any number of arguments in the form of a QList<QVariant>, or QList<QVariant>.

void QxtLogger::disableAllLogLevels ()

Disables all log levels for all named Engines.

void QxtLogger::disableAllLogLevels ( const QString & engineName )

Disables all log levels for the named Engine. engineName The name of an Engine.

void QxtLogger::disableLogLevels ( LogLevels levels )

Unflags the given LogLevels across all Engines. Disables the given LogLevel across all QxtLoggersEngines. Note that some

levels A LogLevel or LogLevels to disable.

void QxtLogger::disableLogLevels ( const QString & engineName, LogLevels levels )

Disables the given LogLevel across the named QxtLoggersEngines. engineName The name of a QxtLoggerEngine. level A LogLevel or LogLevels to disable.

void QxtLogger::disableLoggerEngine ( const QString & engineName )

Disables the named Engine. Disables the the named QxtLoggerEngine if it exists.

engineName The name of a log Engine to disable.

void QxtLogger::enableAllLogLevels ()

Turns on all log levels for all engines. This is a function provided for convenience, and is equivalent to calling:

    qxtLog->enableLogLevels(QxtLogger::AllLevels);

void QxtLogger::enableAllLogLevels ( const QString & engineName )

Turns on all log levels for a named engine. This is a function provided for convenience, and is equivalent to calling:

    qxtLog->enableLogLevels("test", QxtLogger::AllLevels);

void QxtLogger::enableLogLevels ( LogLevels levels )

Enables the given LogLevels across all Engines.

    qxtLog->enableLogLevels(QxtLogger::NoLevels);
    qxtLog->write("I don't do anything!");
    qxtLog->enableLogLevels(QxtLogger::AllLevels);
    qxtLog->write("Hi there!");

levels A bitmask of LogLevels

void QxtLogger::enableLogLevels ( const QString & engineName, LogLevels levels )

Enables the given LogLevels on a named Engine. This will use the given engine name to tell a loaded QxtLoggerEngine what LogLevels it should enable.

    qxtLog->addLoggerEngine("test", "libTestLogger");
    qxtLog->enableLogLevels("test", QxtLoger::AllLevels);
    qxtLog->write("You can see me through your 'test' logger now!");

engineName The name of a QxtLoggerEngine. levels A LogLevel or LogLevels to enable.

******************************************************************************

See also addLoggerEngine().

void QxtLogger::enableLoggerEngine ( const QString & engineName )

Enables a named engine if it is currently disabled. engineName the name of a QxtLoggerEngine.

QxtLoggerEngine * QxtLogger::engine ( const QString & engineName )

Returns the named Engine.

QxtLogStream QxtLogger::error ()

Opens a stream to write a message to all Engines with the ErrorLevel set. The parameterless logging functions return a QxtLogStream for use similar to qDebug().

    qxtLog->error() << "error message";

void QxtLogger::error ( const QVariant & message, const QVariant & msg1 = QVariant(), const QVariant & msg2 = QVariant(), const QVariant & msg3 = QVariant(), const QVariant & msg4 = QVariant(), const QVariant & msg5 = QVariant(), const QVariant & msg6 = QVariant(), const QVariant & msg7 = QVariant(), const QVariant & msg8 = QVariant(), const QVariant & msg9 = QVariant() )   [slot]

Writes a message to all Engines with the ErrorLevel set. The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc currently only accepts functions with up to 10 parameters. They can take any value that QVariant can take as an argument.

void QxtLogger::error ( const QList<QVariant> & args )   [slot]

Writes a message to all Engines with the ErrorLevel set. The 1-parameter logging messages can take any number of arguments in the form of a QList<QVariant>, or QList<QVariant>.

QxtLogStream QxtLogger::fatal ()

Opens a stream to write a message to all Engines with the FatalLevel set. The parameterless logging functions return a QxtLogStream for use similar to qDebug().

    qxtLog->fatal() << "fatal error message";

void QxtLogger::fatal ( const QVariant & message, const QVariant & msg1 = QVariant(), const QVariant & msg2 = QVariant(), const QVariant & msg3 = QVariant(), const QVariant & msg4 = QVariant(), const QVariant & msg5 = QVariant(), const QVariant & msg6 = QVariant(), const QVariant & msg7 = QVariant(), const QVariant & msg8 = QVariant(), const QVariant & msg9 = QVariant() )   [slot]

Writes a message to all Engines with the FatalLevel set. The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc currently only accepts functions with up to 10 parameters. They can take any value that QVariant can take as an argument.

void QxtLogger::fatal ( const QList<QVariant> & args )   [slot]

Writes a message to all Engines with the FatalLevel set. The 1-parameter logging messages can take any number of arguments in the form of a QList<QVariant>, or QList<QVariant>.

QxtLogger * QxtLogger::getInstance ()   [static]

Returns a pointer to the instance of the Logger. QxtLogger is implemented as a singleton, a single object, that manages all of the logging done in an application. The easiest way to use it is by calling the qxtLog macro:

    #include <QxtLogger>
    ...
    qxtLog->info("I can log things!");

qxtLog expands to QxtLogger::getInstance, which returns a pointer to the logger.

QxtLogger manages it's own memory, so please remember the second rule of pointers: don't delete it unless you instantiated it yourself.

    delete qxtLog; // Will horribly crash your app, and possibly your system

QxtLogStream QxtLogger::info ()

Opens a stream to write a message to all Engines with the InfoLevel set. The parameterless logging functions return a QxtLogStream for use similar to qDebug().

    qxtLog->info() << "informational message";

void QxtLogger::info ( const QVariant & message, const QVariant & msg1 = QVariant(), const QVariant & msg2 = QVariant(), const QVariant & msg3 = QVariant(), const QVariant & msg4 = QVariant(), const QVariant & msg5 = QVariant(), const QVariant & msg6 = QVariant(), const QVariant & msg7 = QVariant(), const QVariant & msg8 = QVariant(), const QVariant & msg9 = QVariant() )   [slot]

Writes a message to all Engines with the InfoLevel set. The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc currently only accepts functions with up to 10 parameters. They can take any value that QVariant can take as an argument.

void QxtLogger::info ( const QList<QVariant> & args )   [slot]

Writes a message to all Engines with the InfoLevel set. The 1-parameter logging messages can take any number of arguments in the form of a QList<QVariant>, or QList<QVariant>.

void QxtLogger::initLoggerEngine ( const QString & engineName )

Calls QxtLoggerEngine::initLoggerEngine() for the named Engine. Some QxtLoggerEngine plugins might require additional initialization. Check the documentation for your plugin. Most basic plugins will not require special tasks. engineName The name of a QxtLoggerEngine.

void QxtLogger::installAsMessageHandler ()

Installs QxtLogger as Qt's message handler. This will make Qt macros use QxtLogger instead of the default mechanism:

bool QxtLogger::isLogLevelEnabled ( const QString & engineName, LogLevel level ) const

Checks if the named Engine has the given LogLevel enabled. engineName The name of a QxtLoggerEngine to query level A LogLevel or LogLevels to disable. Returns true or false.

bool QxtLogger::isLoggerEngine ( const QString & engineName ) const

Checks if the given string names a currently loaded Engine. Returns True or false.

bool QxtLogger::isLoggerEngineEnabled ( const QString & engineName ) const

Checks if the named engine is currently enabled. Returns True or false

void QxtLogger::killLoggerEngine ( const QString & engineName )

Calls QxtLoggerEngine::killLoggerEngine() for the named Engine. Some QxtLoggerEngine plugins might require special cleanup before destruction. Check the documentation for your plugin. Most basic plugins will not require this. engineName The name of a QxtLoggerEngine.

void QxtLogger::log ( LogLevel level, const QList<QVariant> & args )   [slot]

A Generic Logging Function that takes a LogLevel and a QList<QVariant> of messages

This function is provided for convenience.

QString QxtLogger::logLevelToString ( LogLevel level )   [static]

Returns a QString of the given LogLevel. This function is provided for convenience.

void QxtLogger::loggerEngineAdded ( const QString & engineName )   [signal]

This signal is emitted when an engine with engineName has been added.

See also loggerEngineRemoved().

void QxtLogger::loggerEngineDisabled ( const QString & engineName )   [signal]

This signal is emitted when an engine with engineName has been disabled.

See also loggerEngineEnabled().

void QxtLogger::loggerEngineEnabled ( const QString & engineName )   [signal]

This signal is emitted when an engine with engineName has been enabled.

See also loggerEngineDisabled().

void QxtLogger::loggerEngineRemoved ( const QString & engineName )   [signal]

This signal is emitted when an engine with engineName has been removed.

See also loggerEngineAdded().

void QxtLogger::removeAsMessageHandler ()

Tells Qt to use it's own message handling again.

void QxtLogger::removeLoggerEngine ( const QString & engineName )

Remove the named Engine from use.

void QxtLogger::removeLoggerEngine ( QxtLoggerEngine * engine )

Remove the Engine from use.

void QxtLogger::setMinimumLevel ( LogLevel level )

Sets the minimumlog level for all Engines, as well as the levels above it. level The single LogLevel to set as minimum.

void QxtLogger::setMinimumLevel ( const QString & engineName, LogLevel level )

Sets the minimumlog level for the named Engine, as well as the levels above it. engineName The name of a QxtLoggerEngine. level The single LogLevel to set as minimum.

QxtLogStream QxtLogger::stream ( LogLevel level )

Returns a reference to a refcounted stream. This is still in its early phases and is in dire need of testing and debugging.

    QxtLogger::stream(QxtLogger::WriteLevel) << "This should write stuff" << 1.5 << QString();

QxtLogger::LogLevel QxtLogger::stringToLogLevel ( const QString & level )   [static]

Returns a LogLevel for the given string, or QxtLogger::NoLevels if invalid. This function is provided for convenience.

QxtLoggerEngine * QxtLogger::takeLoggerEngine ( const QString & engineName )

Take the named Engine.

QxtLogStream QxtLogger::trace ()

Opens a stream to write a message to all Engines with the TraceLevel set. The parameterless logging functions return a QxtLogStream for use similar to qDebug().

    qxtLog->trace() << "detailed trace message";

void QxtLogger::trace ( const QVariant & message, const QVariant & msg1 = QVariant(), const QVariant & msg2 = QVariant(), const QVariant & msg3 = QVariant(), const QVariant & msg4 = QVariant(), const QVariant & msg5 = QVariant(), const QVariant & msg6 = QVariant(), const QVariant & msg7 = QVariant(), const QVariant & msg8 = QVariant(), const QVariant & msg9 = QVariant() )   [slot]

Writes a message to all Engines with the TraceLevel set. The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc currently only accepts functions with up to 10 parameters. They can take any value that QVariant can take as an argument.

void QxtLogger::trace ( const QList<QVariant> & args )   [slot]

Writes a message to all Engines with the TraceLevel set. The 1-parameter logging messages can take any number of arguments in the form of a QList<QVariant>, or QList<QVariant>.

QxtLogStream QxtLogger::warning ()

Opens a stream to write a message to all Engines with the WarningLevel set. The parameterless logging functions return a QxtLogStream for use similar to qDebug().

    qxtLog->warning() << "warning message";

void QxtLogger::warning ( const QVariant & message, const QVariant & msg1 = QVariant(), const QVariant & msg2 = QVariant(), const QVariant & msg3 = QVariant(), const QVariant & msg4 = QVariant(), const QVariant & msg5 = QVariant(), const QVariant & msg6 = QVariant(), const QVariant & msg7 = QVariant(), const QVariant & msg8 = QVariant(), const QVariant & msg9 = QVariant() )   [slot]

Writes a message to all Engines with the WarningLevel set. The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc currently only accepts functions with up to 10 parameters. They can take any value that QVariant can take as an argument.

void QxtLogger::warning ( const QList<QVariant> & args )   [slot]

Writes a message to all Engines with the WarningLevel set. The 1-parameter logging messages can take any number of arguments in the form of a QList<QVariant>, or QList<QVariant>.

QxtLogStream QxtLogger::write ()

Opens a stream to write a message to all Engines with the WriteLevel set. The parameterless logging functions return a QxtLogStream for use similar to qDebug().

    qxtLog->write() << "log message";

void QxtLogger::write ( const QVariant & message, const QVariant & msg1 = QVariant(), const QVariant & msg2 = QVariant(), const QVariant & msg3 = QVariant(), const QVariant & msg4 = QVariant(), const QVariant & msg5 = QVariant(), const QVariant & msg6 = QVariant(), const QVariant & msg7 = QVariant(), const QVariant & msg8 = QVariant(), const QVariant & msg9 = QVariant() )   [slot]

Writes a message to all Engines with the WriteLevel set. The 10-parameter logging functions are designed to be used with Qt's Signals and Slots, since moc currently only accepts functions with up to 10 parameters. They can take any value that QVariant can take as an argument.

void QxtLogger::write ( const QList<QVariant> & args )   [slot]

Writes a message to all Engines with the WriteLevel set. The 1-parameter logging messages can take any number of arguments in the form of a QList<QVariant>, or QList<QVariant>.


Macro Documentation

qxtLog

A global pointer referring to the unique logger object. It is equivalent to the pointer returned by the QxtLogger::instance() function.

See also QxtLogger::getInstance().


Copyright © 2007-2010 Qxt Foundation
Qxt 0.7.0