CuteLogger
Fast and simple logging solution for Qt based applications
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
AbstractStringAppender Class Reference

The AbstractStringAppender class provides a convinient base for appenders working with plain text formatted logs. More...

Inheritance diagram for AbstractStringAppender:
AbstractAppender ConsoleAppender FileAppender OutputDebugAppender RollingFileAppender

Public Member Functions

 AbstractStringAppender ()
 Constructs a new string appender object.
 
virtual QString format () const
 Returns the current log format string. More...
 
void setFormat (const QString &)
 Sets the logging format for writing strings to the log target with this appender. More...
 
- Public Member Functions inherited from AbstractAppender
 AbstractAppender ()
 Constructs a AbstractAppender object.
 
virtual ~AbstractAppender ()
 Destructs the AbstractAppender object.
 
Logger::LogLevel detailsLevel () const
 Returns the current details level of appender. More...
 
void setDetailsLevel (Logger::LogLevel level)
 Sets the current details level of appender. More...
 
void setDetailsLevel (const QString &level)
 Sets the current details level of appender. More...
 
void write (const QDateTime &timeStamp, Logger::LogLevel logLevel, const char *file, int line, const char *function, const QString &category, const QString &message)
 Tries to write the log record to this logger. More...
 

Static Public Member Functions

static QString stripFunctionName (const char *)
 Strips the long function signature (as added by Q_FUNC_INFO macro) More...
 

Protected Member Functions

QString formattedString (const QDateTime &timeStamp, Logger::LogLevel logLevel, const char *file, int line, const char *function, const QString &category, const QString &message) const
 Returns the string to record to the logging target, formatted according to the format(). More...
 
- Protected Member Functions inherited from AbstractAppender
virtual void append (const QDateTime &timeStamp, Logger::LogLevel logLevel, const char *file, int line, const char *function, const QString &category, const QString &message)=0
 Writes the log record to the logger instance. More...
 

Detailed Description

The AbstractStringAppender class provides a convinient base for appenders working with plain text formatted logs.

AbstractSringAppender is the simple extension of the AbstractAppender class providing the convinient way to create custom log appenders working with a plain text formatted log targets.

It have the formattedString() protected function that formats the logging arguments according to a format set with setFormat().

This class can not be directly instantiated because it contains pure virtual function inherited from AbstractAppender class.

For more detailed description of customizing the log output format see the documentation on the setFormat() function.

Member Function Documentation

◆ format()

QString AbstractStringAppender::format ( ) const
virtual

Returns the current log format string.

The default format is set to "%{time}{yyyy-MM-ddTHH:mm:ss.zzz} [%{type:-7}] <%{function}> %{message}\n". You can set a different log record format using the setFormat() function.

See also
setFormat(const QString&)

Reimplemented in ConsoleAppender.

◆ formattedString()

QString AbstractStringAppender::formattedString ( const QDateTime &  timeStamp,
Logger::LogLevel  logLevel,
const char *  file,
int  line,
const char *  function,
const QString &  category,
const QString &  message 
) const
protected

Returns the string to record to the logging target, formatted according to the format().

See also
format()
setFormat(const QString&)

◆ setFormat()

void AbstractStringAppender::setFormat ( const QString &  format)

Sets the logging format for writing strings to the log target with this appender.

The string format seems to be very common to those developers who have used a standart sprintf function.

Log output format is a simple QString with the special markers (starting with % sign) which will be replaced with it's internal meaning when writing a log record.

Controlling marker begins with the percent sign (%) which is followed by the command inside {} brackets (the command describes, what will be put to log record instead of marker). Optional field width argument may be specified right after the command (through the colon symbol before the closing bracket) Some commands requires an additional formatting argument (in the second {} brackets).

Field width argument works almost identically to the QString::arg() fieldWidth argument (and uses it internally). For example, "%{type:-7}" will be replaced with the left padded debug level of the message ("Debug ") or something. For the more detailed description of it you may consider to look to the Qt Reference Documentation.

Supported marker commands are:

  • %{time} - timestamp. You may specify your custom timestamp format using the second {} brackets after the marker, timestamp format here will be similiar to those used in QDateTime::toString() function. For example, "%{time}{dd-MM-yyyy, HH:mm}" may be replaced with "17-12-2010, 20:17" depending on current date and time. The default format used here is "HH:mm:ss.zzz".
  • %{type} - Log level. Possible log levels are shown in the Logger::LogLevel enumerator.
  • %{Type} - Uppercased log level.
  • %{typeOne} - One letter log level.
  • %{TypeOne} - One uppercase letter log level.
  • %{File} - Full source file name (with path) of the file that requested log recording. Uses the FILE preprocessor macro.
  • %{file} - Short file name (with stripped path).
  • %{line} - Line number in the source file. Uses the LINE preprocessor macro.
  • %{Function} - Name of function that called on of the LOG_* macros. Uses the Q_FUNC_INFO macro provided with Qt.
  • %{function} - Similiar to the %{Function}, but the function name is stripped using stripFunctionName
  • %{message} - The log message sent by the caller.
  • %{category} - The log category.
  • %{appname} - Application name (returned by QCoreApplication::applicationName() function).
  • %{pid} - Application pid (returned by QCoreApplication::applicationPid() function).
  • %{threadid} - ID of current thread.
  • %% - Convinient marker that is replaced with the single % mark.
Note
Format doesn't add '\n' to the end of the format line. Please consider adding it manually.
See also
format()
stripFunctionName()
Logger::LogLevel

◆ stripFunctionName()

QString AbstractStringAppender::stripFunctionName ( const char *  name)
static

Strips the long function signature (as added by Q_FUNC_INFO macro)

The string processing drops the returning type, arguments and template parameters of function. It is definitely useful for enchancing the log output readability.

Returns
stripped function name

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