summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/logger/AbstractStringAppender.h
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/logger/AbstractStringAppender.h')
-rw-r--r--rbutil/rbutilqt/logger/AbstractStringAppender.h116
1 files changed, 116 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/logger/AbstractStringAppender.h b/rbutil/rbutilqt/logger/AbstractStringAppender.h
new file mode 100644
index 0000000000..3cef63bff9
--- /dev/null
+++ b/rbutil/rbutilqt/logger/AbstractStringAppender.h
@@ -0,0 +1,116 @@
1/*
2 Copyright (c) 2010 Boris Moiseev (cyberbobs at gmail dot com)
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License version 2.1
6 as published by the Free Software Foundation and appearing in the file
7 LICENSE.LGPL included in the packaging of this file.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13*/
14#ifndef ABSTRACTSTRINGAPPENDER_H
15#define ABSTRACTSTRINGAPPENDER_H
16
17// Local
18#include "CuteLogger_global.h"
19#include <AbstractAppender.h>
20
21// Qt
22#include <QReadWriteLock>
23
24
25//! The AbstractStringAppender class provides a convinient base for appenders working with plain text formatted logs.
26/**
27 * AbstractSringAppender is the simple extension of the AbstractAppender class providing the convinient way to create
28 * custom log appenders working with a plain text formatted log targets.
29 *
30 * It have the formattedString() protected function that formats the logging arguments according to a format set with
31 * setFormat().
32 *
33 * This class can not be directly instantiated because it contains pure virtual function inherited from AbstractAppender
34 * class.
35 *
36 * For more detailed description of customizing the log output format see the documentation on the setFormat() function.
37 */
38class CUTELOGGERSHARED_EXPORT AbstractStringAppender : public AbstractAppender
39{
40 public:
41 //! Constructs a new string appender object
42 AbstractStringAppender();
43
44 //! Returns the current log format string.
45 /**
46 * The default format is set to "%t{yyyy-MM-ddTHH:mm:ss.zzz} [%-7l] <%C> %m\n". You can set a different log record
47 * format using the setFormat() function.
48 *
49 * \sa setFormat(const QString&)
50 */
51 QString format() const;
52
53 //! Sets the logging format for writing strings to the log target with this appender.
54 /**
55 * The string format seems to be very common to those developers who have used a standart sprintf function.
56 *
57 * Log output format is a simple QString with the special markers (starting with % sign) which will be replaced with
58 * it's internal meaning when writing a log record.
59 *
60 * Controlling marker begins with the percent sign (%) which is followed by (optional) field width argument, the
61 * (necessary) single-letter command (which describes, what will be put to log record instead of marker, and an
62 * additional formatting argument (in the {} brackets) supported for some of the log commands.
63 *
64 * Field width argument works almost identically to the \c QString::arg() \c fieldWidth argument (and uses it
65 * internally). For example, \c "%-7l" will be replaced with the left padded debug level of the message
66 * (\c "Debug ") or something. For the more detailed description of it you may consider to look to the Qt
67 * Reference Documentation.
68 *
69 * Supported marker commands are:
70 * \arg \c %t - timestamp. You may specify your custom timestamp format using the {} brackets after the marker,
71 * timestamp format here will be similiar to those used in QDateTime::toString() function. For example,
72 * "%t{dd-MM-yyyy, HH:mm}" may be replaced with "17-12-2010, 20:17" depending on current date and time.
73 * The default format used here is "HH:mm:ss.zzz".
74 * \arg \c %l - Log level. Possible log levels are shown in the Logger::LogLevel enumerator.
75 * \arg \c %L - Uppercased log level.
76 * \arg \c %F - Full source file name (with path) of the file that requested log recording. Uses the \c __FILE__
77 * preprocessor macro.
78 * \arg \c %f - Short file name (with stripped path).
79 * \arg \c %i - Line number in the source file. Uses the \c __LINE__ preprocessor macro.
80 * \arg \c %C - Name of function that called on of the LOG_* macros. Uses the \c Q_FUNC_INFO macro provided with
81 * Qt.
82 * \arg \c %c - [EXPERIMENTAL] Similiar to the %C, but the function name is stripped using stripFunctionName
83 * \arg \c %m - The log message sent by the caller.
84 * \arg \c %% - Convinient marker that is replaced with the single \c % mark.
85 *
86 * \note Format doesn't add \c '\\n' to the end of the format line. Please consider adding it manually.
87 *
88 * \sa format()
89 * \sa stripFunctionName()
90 * \sa Logger::LogLevel
91 */
92 void setFormat(const QString&);
93
94 //! Strips the long function signature (as added by Q_FUNC_INFO macro)
95 /**
96 * The string processing drops the returning type, arguments and template parameters of function. It is definitely
97 * useful for enchancing the log output readability.
98 * \return stripped function name
99 */
100 static QString stripFunctionName(const char*);
101
102 protected:
103 //! Returns the string to record to the logging target, formatted according to the format().
104 /**
105 * \sa format()
106 * \sa setFormat(const QString&)
107 */
108 QString formattedString(const QDateTime& timeStamp, Logger::LogLevel logLevel, const char* file, int line,
109 const char* function, const QString& message) const;
110
111 private:
112 QString m_format;
113 mutable QReadWriteLock m_formatLock;
114};
115
116#endif // ABSTRACTSTRINGAPPENDER_H