DtkCore
DTK Core module
Dtk::Core::AbstractStringAppender类 参考

The AbstractStringAppender class provides a convenient base for appenders working with plain text formatted logs. 更多...

类 Dtk::Core::AbstractStringAppender 继承关系图:
Dtk::Core::AbstractAppender Dtk::Core::ConsoleAppender Dtk::Core::FileAppender Dtk::Core::OutputDebugAppender Dtk::Core::RollingFileAppender

Public 成员函数

 AbstractStringAppender ()
 Constructs a new string appender object.
 
virtual QString format () const
 Returns the current log format string. 更多...
 
void setFormat (const QString &)
 Sets the logging format for writing strings to the log target with this appender. 更多...
 
- Public 成员函数 继承自 Dtk::Core::AbstractAppender
 AbstractAppender ()
 Constructs a AbstractAppender object.
 
virtual ~AbstractAppender ()
 Destructs the AbstractAppender object.
 
Logger::LogLevel detailsLevel () const
 Returns the current details level of appender. 更多...
 
void setDetailsLevel (Logger::LogLevel level)
 Sets the current details level of appender. 更多...
 
void setDetailsLevel (const QString &level)
 Sets the current details level of appender. 更多...
 
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. 更多...
 

静态 Public 成员函数

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

Protected 成员函数

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(). 更多...
 
- Protected 成员函数 继承自 Dtk::Core::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 更多...
 

详细描述

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

\inmodule dtkcore

AbstractSringAppender is the simple extension of the AbstractAppender class providing the convenient 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.

成员函数说明

◆ format()

QString Dtk::Core::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.

参见
setFormat(const QString&)

Dtk::Core::ConsoleAppender 重载.

◆ formattedString()

QString Dtk::Core::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().

timeStamp The time stamp. The logLevel parameter describes the LogLevel, and the file parameter is the current file name, and the line parameter indicates the number of lines to output. The function parameter indicates the function name to output. The category parameter indicates the log category. The message parameter indicates the output message.

参见
format()
setFormat(const QString&)

◆ setFormat()

void Dtk::Core::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 standard 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: \list

  • %{time} - timestamp. You may specify your custom timestamp format using the second {} brackets after the marker,
  • timestamp format here will be similar 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} - Similar 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. \endlist
注解
Format doesn't add '\n' to the end of the format line. Please consider adding it manually.
参见
format()
stripFunctionName()
Logger::LogLevel

◆ stripFunctionName()

QString Dtk::Core::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.

The name parameter is the function name.

返回
stripped function name

该类的文档由以下文件生成: