#include <logerror.h>
Public Types | |
enum | Encoding { LATIN1, CODECFORTR, UNICODEUTF8 } |
Public Member Functions | |
LogError () | |
LogError (const QString &rMessage, int code=0, const QString &rSymbol=QString(), const QString &rContext=QString()) | |
LogError (const char *pMessage, int code=0, const char *pSymbol=0, const char *pContext=0, Encoding encoding=LATIN1) | |
int | code () const |
QString | context () const |
QString | message () const |
QString | symbol () const |
QString | translatedMessage () const |
void | setCode (int code) |
void | setContext (const QString &rClassName) |
void | setMessage (const QString &rMessage) |
void | setSymbol (const QString &rSymbol) |
LogError & | addArg (const QVariant &rArg) |
LogError & | addArg (int arg) |
LogError & | addArg (const QString &rArg) |
LogError & | addCausingError (const LogError &rLogError) |
QList< QVariant > | args () const |
QList< LogError > | causingErrors () const |
void | clearArgs () |
void | clearCausingErrors () |
bool | isEmpty () const |
QString | messageWithArgs () const |
QString | translatedMessageWithArgs () const |
LogError & | operator<< (const QVariant &rArg) |
LogError & | operator<< (int arg) |
LogError & | operator<< (const QString &rArg) |
QString | toString () const |
Static Public Member Functions | |
static LogError | lastError () |
static void | setLastError (const LogError &rLogError) |
Friends | |
QDataStream & | operator<< (QDataStream &rStream, const LogError &rLogError) |
QDataStream & | operator>> (QDataStream &rStream, LogError &rLogError) |
Related Functions | |
(Note that these are not member functions.) | |
QDebug | operator<< (QDebug debug, const LogError &rLogError) |
The class error allows storing error information in a structured way. The error message is stored separately from the information that may be substituted into the message string. This way it is possible to access all information after the error has been raised. It also allows to translate the error at a later point in time or to get a translated and a not translated error text (e.g. translated for the UI and not translated for a log).
The message is accessed using message() and setMessage(). Arguments for the message can be added using addArg() or operator<<(). The arguments can be retrieved using args(). The message with substituted arguments is returned by messageWithArgs().
An error code can be set as integer value code() and/or a symbolic value symbol().
To allow the translation of the message the error stores the translation context (context(), setContext()). The translated message can be accessed using translatedMessage() or using translatedMessageWithArgs(), if it should contain the arguments.
An error can have one or more related errors that caused it. An error is related using addCausingError(). All causing errors can be retrieved using causingErrors().
A per thread error can be maintained using lastError() and setLastError().
There are two macros avaiable to simplify the error creation. The macro LOG4QT_ERROR is used with classes not derived from QObject. The macro LOG4QT_QCLASS_ERROR is used with classes derived from QObject.
The enum Encoding defines the 8-bit encoding of a character string arguments to LogError::LogError(const char *, int, const char *, const char *, Encoding) "LogError::LogError()".
Log4Qt::LogError::LogError | ( | ) |
Creates an empty error. The error code is set to 0 and all other members are set to be empty.
Log4Qt::LogError::LogError | ( | const QString & | rMessage, | |
int | code = 0 , |
|||
const QString & | rSymbol = QString() , |
|||
const QString & | rContext = QString() | |||
) |
Creates an error with the Message rMessage and the error code code. The symbol for the error code is set to rSymbol and the context to rContext.
rContext must be string that can be converted to Latin-1. The Latin-1 representation of the string is used with QApplication::translate(), if a translation for rMessage is requested.
Log4Qt::LogError::LogError | ( | const char * | pMessage, | |
int | code = 0 , |
|||
const char * | pSymbol = 0 , |
|||
const char * | pContext = 0 , |
|||
Encoding | encoding = LATIN1 | |||
) |
Creates an error with the Message pMessage and the error code code. The symbol for the error code is set to pSymbol and the context to pContext.
encoding specifies the encoding of pMessage. pSymbol and pContext are expected to be Latin-1.
int Log4Qt::LogError::code | ( | ) | const [inline] |
QString Log4Qt::LogError::context | ( | ) | const [inline] |
QString Log4Qt::LogError::message | ( | ) | const [inline] |
QString Log4Qt::LogError::symbol | ( | ) | const [inline] |
QString Log4Qt::LogError::translatedMessage | ( | ) | const |
Returns the translated error message.
The translated message is created by calling QCoreApplication::translate() using context().toLatin1() as context and message.toUtf8() as message.
Referenced by translatedMessageWithArgs().
void Log4Qt::LogError::setCode | ( | int | code | ) | [inline] |
void Log4Qt::LogError::setContext | ( | const QString & | rClassName | ) | [inline] |
Sets the context to rClassName.
rContext must be string that can be converted to Latin-1. The Latin-1 representation of the string is used with QApplication::translate(), if a translation for rMessage is requestd.
void Log4Qt::LogError::setMessage | ( | const QString & | rMessage | ) | [inline] |
void Log4Qt::LogError::setSymbol | ( | const QString & | rSymbol | ) | [inline] |
static LogError Log4Qt::LogError::lastError | ( | ) | [static] |
Returns the last error set for the current thread using setLastError().
static void Log4Qt::LogError::setLastError | ( | const LogError & | rLogError | ) | [static] |
Sets the last error for the current thread to rLogError.
LogError & Log4Qt::LogError::addArg | ( | const QVariant & | rArg | ) | [inline] |
Appends rArg to the list of arguments and returns a reference to this error.
Referenced by operator<<().
LogError & Log4Qt::LogError::addArg | ( | int | arg | ) | [inline] |
This is an overloaded member function, provided for convenience.
LogError & Log4Qt::LogError::addArg | ( | const QString & | rArg | ) | [inline] |
This is an overloaded member function, provided for convenience.
Appends rLogError to the list of causing errors and returns a reference to this error.
QList< QVariant > Log4Qt::LogError::args | ( | ) | const [inline] |
Returns the list of arguments that have been added to this error.
QList< LogError > Log4Qt::LogError::causingErrors | ( | ) | const [inline] |
Returns the list of causing errors that have been added to this error.
void Log4Qt::LogError::clearArgs | ( | ) | [inline] |
Clears the list of arguments that have been added to this error.
void Log4Qt::LogError::clearCausingErrors | ( | ) | [inline] |
Clears the list of causing errors that have been added to this error.
bool Log4Qt::LogError::isEmpty | ( | ) | const [inline] |
QString Log4Qt::LogError::messageWithArgs | ( | ) | const [inline] |
Returns the message with arguments. The arguments are incoorporated into the messag using QString::arg().
References message().
QString Log4Qt::LogError::translatedMessageWithArgs | ( | ) | const [inline] |
Returns the translated message with arguments. The arguments are incoorporated into the messag using QString::arg().
References translatedMessage().
LogError & Log4Qt::LogError::operator<< | ( | const QVariant & | rArg | ) | [inline] |
LogError & Log4Qt::LogError::operator<< | ( | int | arg | ) | [inline] |
This is an overloaded member function, provided for convenience.
References addArg().
LogError & Log4Qt::LogError::operator<< | ( | const QString & | rArg | ) | [inline] |
This is an overloaded member function, provided for convenience.
References addArg().
QString Log4Qt::LogError::toString | ( | ) | const |
Returns a string representation of the error.
The string has the following format:
message (context::symbol, code): causing_error, causing_error
If members are empty they are omitted:
Referenced by Log4Qt::Logger::debug(), Log4Qt::Logger::error(), Log4Qt::Logger::fatal(), Log4Qt::Logger::info(), Log4Qt::Logger::log(), Log4Qt::Logger::trace(), and Log4Qt::Logger::warn().
QDataStream & operator<< | ( | QDataStream & | rStream, | |
const LogError & | rLogError | |||
) | [friend] |
Writes the given error rLogError to the given stream rStream, and returns a reference to the stream.
QDataStream & operator>> | ( | QDataStream & | rStream, | |
LogError & | rLogError | |||
) | [friend] |
Reads an error from the given stream rStream into the given error rLogError, and returns a reference to the stream.
QDebug operator<< | ( | QDebug | debug, | |
const LogError & | rLogError | |||
) | [related] |
Writes all object member variables to the given debug stream debug and returns the stream.
LogError(code:7 context:"Log4Qt::FileAppender" message:"Unable to open file '%1' for appender '%2'" symbol:"APPENDER_OPENING_FILE_ERROR" args:(QVariant(QString, "G:\logs\client.log") , QVariant(QString, "Client FileAppender") ) translatedMessage: "Unable to open file '%1' for appender '%2'" )