modernize: Replace most remaining old-style connects by PMF ones
[quassel.git] / src / common / logmessage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program 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         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include "common-export.h"
24
25 #include <QStringList>
26 #include <QTextStream>
27
28 #include "logger.h"
29 #include "types.h"
30
31 /**
32  * Class encapsulating a single log message.
33  *
34  * Very similar in concept to qDebug() and friends.
35  */
36 class COMMON_EXPORT LogMessage
37 {
38 public:
39     LogMessage(Logger::LogLevel level);
40     ~LogMessage();
41
42     template<typename T>
43     LogMessage &operator<<(const T &value) {
44         _stream << value << " ";
45         return *this;
46     }
47
48     LogMessage &operator<<(const QStringList &t);
49     LogMessage &operator<<(bool t);
50
51 private:
52     QTextStream _stream;
53     QString _buffer;
54     Logger::LogLevel _logLevel;
55 };
56
57
58 // The only reason for LogMessage and the helpers below to exist is the fact that Qt versions
59 // prior to 5.5 did not support the Info level.
60 // Once we can rely on Qt 5.5, they will be removed and replaced by the native Qt functions.
61
62 /**
63  * Creates an info-level log message.
64  *
65  * @sa qInfo
66  */
67 class quInfo : public LogMessage
68 {
69 public:
70     quInfo() : LogMessage(Logger::LogLevel::Info) {}
71 };
72
73
74 /**
75  * Creates a warning-level log message.
76  *
77  * @sa qWarning
78  */
79 class quWarning : public LogMessage
80 {
81 public:
82     quWarning() : LogMessage(Logger::LogLevel::Warning) {}
83 };
84
85
86 /**
87  * Creates an error-level log message.
88  *
89  * @sa qCritical
90  */
91 class quError : public LogMessage
92 {
93 public:
94     quError() : LogMessage(Logger::LogLevel::Error) {}
95 };