![]() |
Home · Modules · Classes · Namespaces · Functions |
The QxtLogger class is an easy to use, easy to extend logging tool. More...
#include <QxtLogger>
Inherits QObject.
The QxtLogger class is an easy to use, easy to extend logging tool.
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
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.
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().
The LogLevels type is a typedef for QFlags<LogLevel>. It stores an OR combination of LogLevel values.
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.
Retuns a QStringList containing the names of all loaded Engines that are currently disabled. Returns QStringList engine names.
Retuns a QStringList containing the names of all loaded Engines that are currently enabled. Returns QStringList engine names.
Retuns a QStringList containing the names of all loaded Engines that have currently certain log level enabled. Returns QStringList engine names.
Retuns a QStringList containing the names of all loaded Engines being managed by QxtLogger. Returns QStringList engine names.
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";
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.
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>.
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";
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.
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>.
Disables all log levels for all named Engines.
Disables all log levels for the named Engine. engineName The name of an Engine.
Unflags the given LogLevels across all Engines. Disables the given LogLevel across all QxtLoggersEngines. Note that some
levels A LogLevel or LogLevels to disable.
Disables the given LogLevel across the named QxtLoggersEngines. engineName The name of a QxtLoggerEngine. level A LogLevel or LogLevels to disable.
Disables the named Engine. Disables the the named QxtLoggerEngine if it exists.
engineName The name of a log Engine to disable.
Turns on all log levels for all engines. This is a function provided for convenience, and is equivalent to calling:
qxtLog->enableLogLevels(QxtLogger::AllLevels);
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);
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
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().
Enables a named engine if it is currently disabled. engineName the name of a QxtLoggerEngine.
Returns the named Engine.
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";
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.
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>.
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";
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.
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>.
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
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";
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.
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>.
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.
Installs QxtLogger as Qt's message handler. This will make Qt macros use QxtLogger instead of the default mechanism:
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.
Checks if the given string names a currently loaded Engine. Returns True or false.
Checks if the named engine is currently enabled. Returns True or false
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.
A Generic Logging Function that takes a LogLevel and a QList<QVariant> of messages
This function is provided for convenience.
Returns a QString of the given LogLevel. This function is provided for convenience.
This signal is emitted when an engine with engineName has been added.
See also loggerEngineRemoved().
This signal is emitted when an engine with engineName has been disabled.
See also loggerEngineEnabled().
This signal is emitted when an engine with engineName has been enabled.
See also loggerEngineDisabled().
This signal is emitted when an engine with engineName has been removed.
See also loggerEngineAdded().
Tells Qt to use it's own message handling again.
Remove the named Engine from use.
Remove the Engine from use.
Sets the minimumlog level for all Engines, as well as the levels above it. level The single LogLevel to set as minimum.
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.
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();
Returns a LogLevel for the given string, or QxtLogger::NoLevels if invalid. This function is provided for convenience.
Take the named Engine.
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";
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.
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>.
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";
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.
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>.
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";
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.
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>.
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.6.1 |