Log4Qt::LogError Class Reference

The class LogError represents an error. More...

#include <logerror.h>

List of all members.

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)
LogErroraddArg (const QVariant &rArg)
LogErroraddArg (int arg)
LogErroraddArg (const QString &rArg)
LogErroraddCausingError (const LogError &rLogError)
QList< QVariant > args () const
QList< LogErrorcausingErrors () const
void clearArgs ()
void clearCausingErrors ()
bool isEmpty () const
QString messageWithArgs () const
QString translatedMessageWithArgs () const
LogErroroperator<< (const QVariant &rArg)
LogErroroperator<< (int arg)
LogErroroperator<< (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)


Detailed Description

The class LogError represents an error.

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.


Member Enumeration Documentation

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()".

See also:
LogError::LogError()
Enumerator:
LATIN1  LATIN-1
CODECFORTR  The encoding specified by QTextCodec::codecForTr() (Latin-1 if none has been set).
UNICODEUTF8  UTF-8


Constructor & Destructor Documentation

Log4Qt::LogError::LogError (  ) 

Creates an empty error. The error code is set to 0 and all other members are set to be empty.

See also:
isEmpty()

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.

See also:
translatedMessage(), translatedMessageWithArgs()

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.

Note:
To support the macros LOG4QT_ERROR and LOG4QT_QCLASS_ERROR the function tests, if pSymbol is the string representation of code. If it is, the symbol is set to be empty. Otherwise symbol is set to pSymbol.
See also:
translatedMessage(), translatedMessageWithArgs()


Member Function Documentation

int Log4Qt::LogError::code (  )  const [inline]

Returns the error code.

See also:
setCode()

QString Log4Qt::LogError::context (  )  const [inline]

Returns the context for the error.

See also:
setContext()

QString Log4Qt::LogError::message (  )  const [inline]

Returns the error message.

See also:
setMessage()

Referenced by messageWithArgs().

QString Log4Qt::LogError::symbol (  )  const [inline]

Returns the symbol for the error code.

See also:
setSymbol()

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.

See also:
translatedMessageWithArgs()

Referenced by translatedMessageWithArgs().

void Log4Qt::LogError::setCode ( int  code  )  [inline]

Sets the error code to code.

See also:
code()

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.

See also:
context(), translatedMessage(), translatedMessageWithArgs()

void Log4Qt::LogError::setMessage ( const QString &  rMessage  )  [inline]

Sets the error message to rMessage

See also:
message()

void Log4Qt::LogError::setSymbol ( const QString &  rSymbol  )  [inline]

Sets the symbol for the error code to rSymbol.

See also:
symbol()

static LogError Log4Qt::LogError::lastError (  )  [static]

Returns the last error set for the current thread using setLastError().

Note:
: This function is thread-safe.
See also:
setLastError()

static void Log4Qt::LogError::setLastError ( const LogError rLogError  )  [static]

Sets the last error for the current thread to rLogError.

Note:
: This function is thread-safe.
See also:
lastError()

LogError & Log4Qt::LogError::addArg ( const QVariant &  rArg  )  [inline]

Appends rArg to the list of arguments and returns a reference to this error.

See also:
operator<<(), args(), clearArgs()

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.

LogError & Log4Qt::LogError::addCausingError ( const LogError rLogError  )  [inline]

Appends rLogError to the list of causing errors and returns a reference to this error.

See also:
causingErrors(), clearCausingErrors()

QList< QVariant > Log4Qt::LogError::args (  )  const [inline]

Returns the list of arguments that have been added to this error.

See also:
addArg(), operator<<(), clearArgs()

QList< LogError > Log4Qt::LogError::causingErrors (  )  const [inline]

Returns the list of causing errors that have been added to this error.

See also:
addArg(), operator<<(), clearArgs()

void Log4Qt::LogError::clearArgs (  )  [inline]

Clears the list of arguments that have been added to this error.

See also:
addArg(), operator<<(), args()

void Log4Qt::LogError::clearCausingErrors (  )  [inline]

Clears the list of causing errors that have been added to this error.

See also:
addCausingError(), causingErrors()

bool Log4Qt::LogError::isEmpty (  )  const [inline]

Returns true, if the error code is 0 and the message is empty. Otherwise it returns false.

See also:
code(), message()

QString Log4Qt::LogError::messageWithArgs (  )  const [inline]

Returns the message with arguments. The arguments are incoorporated into the messag using QString::arg().

See also:
QString::arg(), translatedMessageWithArgs()

References message().

QString Log4Qt::LogError::translatedMessageWithArgs (  )  const [inline]

Returns the translated message with arguments. The arguments are incoorporated into the messag using QString::arg().

See also:
QString::arg(), messageWithArgs(), translatedMessage()

References translatedMessage().

LogError & Log4Qt::LogError::operator<< ( const QVariant &  rArg  )  [inline]

Appends rArg to the list of arguments and returns a reference to this error.

See also:
addArg()

References addArg().

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:

  • Omit context, if empty
  • Omit symbol, if empty
  • Omit double colon with context and symbol, if both are empty
  • Omit code, if 0
  • Omit bracket with context/symbol and code, if all are empty
  • Omit colon with causing errors, if no causing errors exist

Referenced by Log4Qt::Logger::debug(), Log4Qt::Logger::error(), Log4Qt::Logger::fatal(), Log4Qt::Logger::info(), Log4Qt::Logger::log(), Log4Qt::Logger::trace(), and Log4Qt::Logger::warn().


Friends And Related Function Documentation

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'" )

See also:
QDebug


The documentation for this class was generated from the following file:

Generated on Sun Mar 1 16:40:45 2009 for Log4Qt by  doxygen 1.5.6