log.h
1 //------------------------------------------------------------------------------
2 // log.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2009 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __LOG_H_
24 #define __LOG_H_
25 
26 #define gLog Log::instance
27 
28 #include "dptr.h"
29 #include "global.h"
30 #include <QMutex>
31 #include <QObject>
32 
37 class MAIN_EXPORT Log : public QObject
38 {
39  Q_OBJECT
40 
41 public:
45  static Log instance;
46 
47  Log();
48  virtual ~Log() override;
49 
53  bool areTimestampsEnabled() const;
54 
58  const QString &content() const;
59 
66  bool isPrintingToStderr() const;
67  void setPrintingToStderr(bool b);
68 
77  bool isPrintingToStdout() const;
81  void setPrintingToStdout(bool b);
82 
83  void setTimestampsEnabled(bool b);
84 
88  Log &operator<<(const QString &string);
89 
90 public slots:
97  void addEntry(const QString &string);
98 
104  void addUnformattedEntry(const QString &string);
105 
109  void clearContent();
110 
111 signals:
117  void newEntry(const QString &entry);
118 
119 private:
120  DPtr<Log> d;
121 };
122 
123 #endif