2020-10-01 00:33:19 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
|
|
|
|
SPDX-FileCopyrightText: 2014-2018 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
SPDX-FileCopyrightText: 2015 Chris Campbell <c.j.campbell@ed.ac.uk>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2018-07-14 21:36:13 +01:00
|
|
|
#ifndef KPMCORE_GLOBALLOG_H
|
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
|