2015-06-04 01:29:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
|
|
|
|
2017-09-10 20:12:52 +01:00
|
|
|
#if !defined(KPMCORE_GLOBALLOG_H)
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2017-09-10 20:12:52 +01:00
|
|
|
#define KPMCORE_GLOBALLOG_H
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-05-04 22:14:38 +01:00
|
|
|
#include "util/libpartitionmanagerexport.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QObject>
|
2016-04-18 17:14:31 +01:00
|
|
|
#include <QtGlobal>
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
class LIBKPMCORE_EXPORT Log
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
public:
|
2018-04-09 15:14:34 +01:00
|
|
|
enum class Level {
|
|
|
|
debug,
|
|
|
|
information,
|
|
|
|
warning,
|
|
|
|
error,
|
2015-07-13 15:16:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2018-04-09 15:14:34 +01:00
|
|
|
Log(Level lev = Level::information) : ref(1), level(lev) {}
|
2015-07-13 15:16:36 +01:00
|
|
|
~Log();
|
|
|
|
Log(const Log& other) : ref(other.ref + 1), level(other.level) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
quint32 ref;
|
|
|
|
Level level;
|
2015-06-04 01:29:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Global logging.
|
2015-07-13 15:16:36 +01:00
|
|
|
@author Volker Lanz <vl@fidra.de>
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
class LIBKPMCORE_EXPORT GlobalLog : public QObject
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_OBJECT
|
|
|
|
Q_DISABLE_COPY(GlobalLog)
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
friend class Log;
|
|
|
|
friend Log operator<<(Log l, const QString& s);
|
|
|
|
friend Log operator<<(Log l, qint64 i);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
private:
|
|
|
|
GlobalLog() : msg() {}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_SIGNALS:
|
|
|
|
void newMessage(Log::Level, const QString&);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
public:
|
|
|
|
static GlobalLog* instance();
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
private:
|
|
|
|
void append(const QString& s) {
|
|
|
|
msg += s;
|
|
|
|
}
|
|
|
|
void flush(Log::Level level);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
private:
|
|
|
|
QString msg;
|
2015-06-04 01:29:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
inline Log operator<<(Log l, const QString& s)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
GlobalLog::instance()->append(s);
|
|
|
|
return l;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline Log operator<<(Log l, qint64 i)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
GlobalLog::instance()->append(QString::number(i));
|
|
|
|
return l;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|