Sayonara Player
Logger.h
1 /* Logger.h */
2 
3 /* Copyright (C) 2011-2016 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 
25 #include <ostream>
26 #include <QString>
27 #include <QStringList>
28 #include <QByteArray>
29 #include <QPoint>
30 
31 
36 enum class Log : unsigned char
37 {
38  Warning,
39  Error,
40  Info,
41  Debug
42 };
43 
48 class Logger{
49 
50 protected:
51  std::ostream& _out;
52 
53 public:
54 
55  Logger(std::ostream& out);
56  Logger(const char* msg, std::ostream& out);
57 
58  ~Logger();
59 
60  Logger& operator << (const QString& msg);
61  Logger& operator << (const QChar& c);
62  Logger& operator << (const QStringList& lst);
63  Logger& operator << (const QByteArray& arr);
64  Logger& operator << (const QPoint& point);
65 
66  template <typename T>
67  Logger& operator << (const T& msg){
68  _out << msg;
69  return *this;
70  }
71 
72  template<typename T, template <typename ELEM> class CONT>
73  Logger& operator << (const CONT<T> list){
74 
75  for(const T& item : list){
76  (*this) << item << ", ";
77  }
78 
79  return *this;
80  }
81 };
82 
83 Logger sp_log(Log type);
84 Logger sp_log(Log type, const QString& module);
85 #endif // LOGGER_H
The Logger class.
Definition: Logger.h:48
Log
The Log enum.
Definition: Logger.h:36