TreeFrogFramework 2.10
Loading...
Searching...
No Matches
tdebug.h
Go to the documentation of this file.
1#pragma once
2#include "tfnamespace.h"
3#include <QString>
4#include <QTextStream>
5#include <QtCore>
6#include <TGlobal>
7
8class TLogger;
9
10namespace Tf {
11
12T_CORE_EXPORT void setupAppLoggers(TLogger *logger = nullptr); // internal use
13T_CORE_EXPORT void releaseAppLoggers(); // internal use
14T_CORE_EXPORT void logging(int priority, const QByteArray &msg);
15
16}
17
18
20public:
21 TDebug(int priority) :
22 msgPriority(priority) {}
23 TDebug(const TDebug &other);
24 ~TDebug();
25 TDebug &operator=(const TDebug &other);
26
27 inline TDebug fatal() const { return TDebug(Tf::FatalLevel); }
28 inline TDebug error() const { return TDebug(Tf::ErrorLevel); }
29 inline TDebug warn() const { return TDebug(Tf::WarnLevel); }
30 inline TDebug info() const { return TDebug(Tf::InfoLevel); }
31 inline TDebug debug() const { return TDebug(Tf::DebugLevel); }
32 inline TDebug trace() const { return TDebug(Tf::TraceLevel); }
33
34 void fatal(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
35 void error(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
36 void warn(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
37 void info(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
38 void debug(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
39 void trace(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
40
41 inline TDebug &operator<<(QChar t)
42 {
43 ts << t;
44 return *this;
45 }
46 inline TDebug &operator<<(bool t)
47 {
48 ts << (t ? "true" : "false");
49 return *this;
50 }
51 inline TDebug &operator<<(char t)
52 {
53 ts << t;
54 return *this;
55 }
56 inline TDebug &operator<<(short t)
57 {
58 ts << t;
59 return *this;
60 }
61 inline TDebug &operator<<(unsigned short t)
62 {
63 ts << t;
64 return *this;
65 }
66 inline TDebug &operator<<(int t)
67 {
68 ts << t;
69 return *this;
70 }
71 inline TDebug &operator<<(unsigned int t)
72 {
73 ts << t;
74 return *this;
75 }
76 inline TDebug &operator<<(long t)
77 {
78 ts << t;
79 return *this;
80 }
81 inline TDebug &operator<<(unsigned long t)
82 {
83 ts << t;
84 return *this;
85 }
86 inline TDebug &operator<<(qint64 t)
87 {
88 ts << t;
89 return *this;
90 }
91 inline TDebug &operator<<(quint64 t)
92 {
93 ts << t;
94 return *this;
95 }
96 inline TDebug &operator<<(float t)
97 {
98 ts << t;
99 return *this;
100 }
101 inline TDebug &operator<<(double t)
102 {
103 ts << t;
104 return *this;
105 }
106 inline TDebug &operator<<(const char *t)
107 {
108 ts << t;
109 return *this;
110 }
111 inline TDebug &operator<<(const QString &t)
112 {
113 ts << t;
114 return *this;
115 }
116 inline TDebug &operator<<(const QLatin1String &t)
117 {
118 ts << t;
119 return *this;
120 }
121 inline TDebug &operator<<(const QStringList &t)
122 {
123 QString str;
124 for (auto &s : t) {
125 str += "\"";
126 str += s;
127 str += "\", ";
128 }
129 str.chop(2);
130 ts << "[" << str << "]";
131 return *this;
132 }
133 inline TDebug &operator<<(const QByteArray &t)
134 {
135 ts << t;
136 return *this;
137 }
138 inline TDebug &operator<<(const QByteArrayList &t)
139 {
140 QByteArray str;
141 for (auto &s : t) {
142 str += "\"";
143 str += s;
144 str += "\", ";
145 }
146 str.chop(2);
147 ts << '[' << str << ']';
148 return *this;
149 }
150 inline TDebug &operator<<(const QVariant &t)
151 {
152 ts << t.toString();
153 return *this;
154 }
155 inline TDebug &operator<<(const void *t)
156 {
157 ts << t;
158 return *this;
159 }
160 inline TDebug &operator<<(std::nullptr_t)
161 {
162 ts << "(nullptr)";
163 return *this;
164 }
165
166private:
167 QString buffer;
168 QTextStream ts {&buffer, Tf::WriteOnly};
169 int msgPriority {0};
170};
The TDebug class provides a file output stream for debugging information.
Definition tdebug.h:19
TDebug & operator<<(bool t)
Definition tdebug.h:46
TDebug & operator<<(double t)
Definition tdebug.h:101
TDebug & operator<<(quint64 t)
Definition tdebug.h:91
TDebug & operator<<(char t)
Definition tdebug.h:51
TDebug & operator<<(unsigned int t)
Definition tdebug.h:71
TDebug fatal() const
Definition tdebug.h:27
TDebug & operator<<(int t)
Definition tdebug.h:66
TDebug & operator<<(const QVariant &t)
Definition tdebug.h:150
TDebug error() const
Definition tdebug.h:28
TDebug & operator<<(short t)
Definition tdebug.h:56
TDebug trace() const
Definition tdebug.h:32
TDebug & operator<<(const QByteArray &t)
Definition tdebug.h:133
TDebug & operator<<(const QString &t)
Definition tdebug.h:111
TDebug info() const
Definition tdebug.h:30
TDebug & operator<<(unsigned long t)
Definition tdebug.h:81
TDebug & operator<<(const char *t)
Definition tdebug.h:106
TDebug & operator<<(qint64 t)
Definition tdebug.h:86
TDebug & operator<<(std::nullptr_t)
Definition tdebug.h:160
TDebug & operator<<(unsigned short t)
Definition tdebug.h:61
TDebug & operator<<(float t)
Definition tdebug.h:96
TDebug & operator<<(const QLatin1String &t)
Definition tdebug.h:116
TDebug warn() const
Definition tdebug.h:29
TDebug(int priority)
Definition tdebug.h:21
TDebug & operator<<(const void *t)
Definition tdebug.h:155
TDebug debug() const
Definition tdebug.h:31
TDebug & operator<<(const QByteArrayList &t)
Definition tdebug.h:138
TDebug & operator<<(long t)
Definition tdebug.h:76
TDebug & operator<<(const QStringList &t)
Definition tdebug.h:121
The TLogger class provides an abstract base of logging functionality.
Definition tlogger.h:19
The Tf namespace contains miscellaneous identifiers used throughout the library of TreeFrog Framework...
Definition tdebug.h:10
T_CORE_EXPORT void releaseAppLoggers()
Releases all the loggers.
Definition tdebug.cpp:87
T_CORE_EXPORT void setupAppLoggers(TLogger *logger=nullptr)
Sets up all the loggers set in the logger.ini.
Definition tdebug.cpp:51
constexpr auto WriteOnly
Definition tfnamespace.h:258
@ TraceLevel
Finer-grained informational events than the DEBUG.
Definition tfnamespace.h:236
@ WarnLevel
Potentially harmful situations.
Definition tfnamespace.h:233
@ DebugLevel
Informational events that are most useful to debug the app.
Definition tfnamespace.h:235
@ InfoLevel
Informational messages that highlight the progress of the app.
Definition tfnamespace.h:234
@ FatalLevel
Severe error events that will presumably lead the app to abort.
Definition tfnamespace.h:231
@ ErrorLevel
Error events that might still allow the app to continue running.
Definition tfnamespace.h:232
T_CORE_EXPORT void logging(int priority, const QByteArray &msg)
Definition tdebug.cpp:99
#define T_CORE_EXPORT
Definition tdeclexport.h:28
#define T_ATTRIBUTE_FORMAT(A, B)
Definition tglobal.h:43