TreeFrogFramework  2.8
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 
8 class TLogger;
9 
10 namespace Tf {
11 
12 T_CORE_EXPORT void setupAppLoggers(TLogger *logger = nullptr); // internal use
13 T_CORE_EXPORT void releaseAppLoggers(); // internal use
14 
15 }
16 
17 
19 public:
20  TDebug(int priority) :
21  msgPriority(priority) {}
22  TDebug(const TDebug &other);
23  ~TDebug();
24  TDebug &operator=(const TDebug &other);
25 
26  inline TDebug fatal() const { return TDebug(Tf::FatalLevel); }
27  inline TDebug error() const { return TDebug(Tf::ErrorLevel); }
28  inline TDebug warn() const { return TDebug(Tf::WarnLevel); }
29  inline TDebug info() const { return TDebug(Tf::InfoLevel); }
30  inline TDebug debug() const { return TDebug(Tf::DebugLevel); }
31  inline TDebug trace() const { return TDebug(Tf::TraceLevel); }
32 
33  void fatal(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
34  void error(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
35  void warn(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
36  void info(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
37  void debug(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
38  void trace(const char *fmt, ...) const T_ATTRIBUTE_FORMAT(2, 3);
39 
40  inline TDebug &operator<<(QChar t)
41  {
42  ts << t;
43  return *this;
44  }
45  inline TDebug &operator<<(bool t)
46  {
47  ts << (t ? "true" : "false");
48  return *this;
49  }
50  inline TDebug &operator<<(char t)
51  {
52  ts << t;
53  return *this;
54  }
55  inline TDebug &operator<<(short t)
56  {
57  ts << t;
58  return *this;
59  }
60  inline TDebug &operator<<(unsigned short t)
61  {
62  ts << t;
63  return *this;
64  }
65  inline TDebug &operator<<(int t)
66  {
67  ts << t;
68  return *this;
69  }
70  inline TDebug &operator<<(unsigned int t)
71  {
72  ts << t;
73  return *this;
74  }
75  inline TDebug &operator<<(long t)
76  {
77  ts << t;
78  return *this;
79  }
80  inline TDebug &operator<<(unsigned long t)
81  {
82  ts << t;
83  return *this;
84  }
85  inline TDebug &operator<<(qint64 t)
86  {
87  ts << t;
88  return *this;
89  }
90  inline TDebug &operator<<(quint64 t)
91  {
92  ts << t;
93  return *this;
94  }
95  inline TDebug &operator<<(float t)
96  {
97  ts << t;
98  return *this;
99  }
100  inline TDebug &operator<<(double t)
101  {
102  ts << t;
103  return *this;
104  }
105  inline TDebug &operator<<(const char *t)
106  {
107  ts << t;
108  return *this;
109  }
110  inline TDebug &operator<<(const QString &t)
111  {
112  ts << t;
113  return *this;
114  }
115 #if QT_VERSION < 0x060000
116  inline TDebug &operator<<(const QStringRef &t)
117  {
118  ts << t.toString();
119  return *this;
120  }
121 #endif
122  inline TDebug &operator<<(const QLatin1String &t)
123  {
124  ts << t;
125  return *this;
126  }
127  inline TDebug &operator<<(const QStringList &t)
128  {
129  QString str;
130  for (auto &s : t) {
131  str += "\"";
132  str += s;
133  str += "\", ";
134  }
135  str.chop(2);
136  ts << "[" << str << "]";
137  return *this;
138  }
139  inline TDebug &operator<<(const QByteArray &t)
140  {
141  ts << t;
142  return *this;
143  }
144  inline TDebug &operator<<(const QByteArrayList &t)
145  {
146  QByteArray str;
147  for (auto &s : t) {
148  str += "\"";
149  str += s;
150  str += "\", ";
151  }
152  str.chop(2);
153  ts << '[' << str << ']';
154  return *this;
155  }
156  inline TDebug &operator<<(const QVariant &t)
157  {
158  ts << t.toString();
159  return *this;
160  }
161  inline TDebug &operator<<(const void *t)
162  {
163  ts << t;
164  return *this;
165  }
166  inline TDebug &operator<<(std::nullptr_t)
167  {
168  ts << "(nullptr)";
169  return *this;
170  }
171 
172 private:
173  QString buffer;
174  QTextStream ts {&buffer, Tf::WriteOnly};
175  int msgPriority {0};
176 };
The TDebug class provides a file output stream for debugging information.
Definition: tdebug.h:18
TDebug & operator<<(unsigned long t)
Definition: tdebug.h:80
TDebug & operator<<(float t)
Definition: tdebug.h:95
TDebug & operator<<(quint64 t)
Definition: tdebug.h:90
TDebug & operator<<(unsigned short t)
Definition: tdebug.h:60
TDebug & operator<<(const QStringList &t)
Definition: tdebug.h:127
TDebug fatal() const
Definition: tdebug.h:26
TDebug & operator<<(const QVariant &t)
Definition: tdebug.h:156
TDebug & operator<<(long t)
Definition: tdebug.h:75
TDebug & operator<<(double t)
Definition: tdebug.h:100
TDebug error() const
Definition: tdebug.h:27
TDebug & operator<<(char t)
Definition: tdebug.h:50
TDebug & operator<<(const QString &t)
Definition: tdebug.h:110
TDebug trace() const
Definition: tdebug.h:31
TDebug & operator<<(const void *t)
Definition: tdebug.h:161
TDebug & operator<<(const QByteArray &t)
Definition: tdebug.h:139
TDebug & operator<<(const QByteArrayList &t)
Definition: tdebug.h:144
TDebug info() const
Definition: tdebug.h:29
TDebug & operator<<(short t)
Definition: tdebug.h:55
TDebug & operator<<(qint64 t)
Definition: tdebug.h:85
TDebug & operator<<(unsigned int t)
Definition: tdebug.h:70
TDebug & operator<<(bool t)
Definition: tdebug.h:45
TDebug warn() const
Definition: tdebug.h:28
TDebug(int priority)
Definition: tdebug.h:20
TDebug debug() const
Definition: tdebug.h:30
TDebug & operator<<(const QLatin1String &t)
Definition: tdebug.h:122
TDebug & operator<<(const char *t)
Definition: tdebug.h:105
TDebug & operator<<(int t)
Definition: tdebug.h:65
TDebug & operator<<(std::nullptr_t)
Definition: tdebug.h:166
The TLogger class provides an abstract base of logging functionality.
Definition: tlogger.h:21
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: tglobal.h:246
@ 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
#define T_CORE_EXPORT
Definition: tdeclexport.h:28
#define T_ATTRIBUTE_FORMAT(A, B)
Definition: tglobal.h:50
QDataStream & operator<<(QDataStream &out, const TLog &log)
Definition: tlog.cpp:40