Sayonara Player
Loading...
Searching...
No Matches
Logger.h
1/* Logger.h */
2
3/* Copyright (C) 2011-2024 Michael Lugmair (Lucio Carreras)
4 *
5 * This file is part of sayonara player
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef LOGGER_H
22#define LOGGER_H
23
24#include <typeinfo>
25#include <type_traits>
26#include <string>
27#include <QString>
28#include <QMetaType>
29
34class QString;
35class QStringList;
36class QByteArray;
37class QPoint;
38class QChar;
39class LogListener;
40class QRegion;
41class QMargins;
42class QSize;
43class QRect;
44
45enum class Log :
46 unsigned char
47{
48 Warning = 0,
49 Error,
50 Info,
51 Debug,
52 Develop,
53 Crazy,
54 Always
55};
56
61class Logger
62{
63
64 private:
65 struct Private;
66 Private* m = nullptr;
67
68 public:
69 explicit Logger(const Log& type, const QString& class_name);
70
71 ~Logger();
72
73 static void registerLogListener(LogListener* logListener);
74
75 Logger& operator<<(const QString& msg);
76 Logger& operator<<(const QChar& c);
77 Logger& operator<<(const QStringList& lst);
78 Logger& operator<<(const QByteArray& arr);
79 Logger& operator<<(const QPoint& point);
80 Logger& operator<<(const QSize& size);
81 Logger& operator<<(const QRect& size);
82 Logger& operator<<(const char* str);
83 Logger& operator<<(const std::string& str);
84 Logger& operator<<(const Log& log_type);
85
86 template<typename T>
87 typename std::enable_if<std::is_floating_point<T>::value, Logger&>::type
88 operator<<(const T& val)
89 {
90
91 (*this) << std::to_string(val);
92
93 return *this;
94 }
95
96 template<typename T>
97 typename std::enable_if<std::is_integral<T>::value, Logger&>::type
98 operator<<(const T& val)
99 {
100
101 (*this) << std::to_string(val);
102
103 return *this;
104 }
105
106 template<typename T, template<typename ELEM> class CONT>
107 Logger& operator<<(const CONT<T>& list)
108 {
109 for(const T& item: list)
110 {
111 (*this) << item << ", ";
112 }
113
114 return *this;
115 }
116};
117
118Logger spLog(const Log& type, const std::string& data);
119Logger spLog(const Log& type, const char* data);
120
121template<typename T>
122typename std::enable_if<std::is_class<T>::value, Logger>::type
123spLog(const Log& type, const T*)
124{
125 return spLog(type, typeid(T).name());
126}
127
128Q_DECLARE_METATYPE(Log)
129
130#endif // LOGGER_H
Definition LogListener.h:33
The Logger class.
Definition Logger.h:62