modernize: Reformat ALL the source... again!
[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     {
45         _stream << value << " ";
46         return *this;
47     }
48
49     LogMessage& operator<<(const QStringList& t);
50     LogMessage& operator<<(bool t);
51
52 private:
53     QTextStream _stream;
54     QString _buffer;
55     Logger::LogLevel _logLevel;
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()
71         : LogMessage(Logger::LogLevel::Info)
72     {}
73 };
74
75 /**
76  * Creates a warning-level log message.
77  *
78  * @sa qWarning
79  */
80 class quWarning : public LogMessage
81 {
82 public:
83     quWarning()
84         : LogMessage(Logger::LogLevel::Warning)
85     {}
86 };
87
88 /**
89  * Creates an error-level log message.
90  *
91  * @sa qCritical
92  */
93 class quError : public LogMessage
94 {
95 public:
96     quError()
97         : LogMessage(Logger::LogLevel::Error)
98     {}
99 };