qa: Remove lots of superfluous semicolons
[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 <QStringList>
24 #include <QTextStream>
25
26 #include "logger.h"
27 #include "types.h"
28
29 /**
30  * Class encapsulating a single log message.
31  *
32  * Very similar in concept to qDebug() and friends.
33  */
34 class LogMessage
35 {
36 public:
37     LogMessage(Logger::LogLevel level);
38     ~LogMessage();
39
40     template<typename T>
41     LogMessage &operator<<(const T &value) {
42         _stream << value << " ";
43         return *this;
44     }
45
46     LogMessage &operator<<(const QStringList &t);
47     LogMessage &operator<<(bool t);
48
49 private:
50     QTextStream _stream;
51     QString _buffer;
52     Logger::LogLevel _logLevel;
53 };
54
55
56 // The only reason for LogMessage and the helpers below to exist is the fact that Qt versions
57 // prior to 5.5 did not support the Info level.
58 // Once we can rely on Qt 5.5, they will be removed and replaced by the native Qt functions.
59
60 /**
61  * Creates an info-level log message.
62  *
63  * @sa qInfo
64  */
65 class quInfo : public LogMessage
66 {
67 public:
68     quInfo() : LogMessage(Logger::LogLevel::Info) {}
69 };
70
71
72 /**
73  * Creates a warning-level log message.
74  *
75  * @sa qWarning
76  */
77 class quWarning : public LogMessage
78 {
79 public:
80     quWarning() : LogMessage(Logger::LogLevel::Warning) {}
81 };
82
83
84 /**
85  * Creates an error-level log message.
86  *
87  * @sa qCritical
88  */
89 class quError : public LogMessage
90 {
91 public:
92     quError() : LogMessage(Logger::LogLevel::Error) {}
93 };