Projekt

Allgemein

Profil

Herunterladen als
Herunterladen (1,78 KB) Statistiken
| Zweig: | Revision:
38838b5b Christian Ehringfeld
/*
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* 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 Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
100034b7 Christian Ehringfeld
#ifndef LOGGER_H
#define LOGGER_H
40cf6a8c SebastianDiel
#define DIFFABLEOUTPUT
100034b7 Christian Ehringfeld
#include <QString>
#include <QFile>
#include <QSqlError>
#include <QSqlQuery>
2b455197 Christian Ehringfeld
namespace CuteEntityManager {
f12670e9 Christian Ehringfeld
enum class MsgType { DEBUG, INFO, WARNING, CRITICAL, FATAL};

66704054 Christian Ehringfeld
class Logger {
f12670e9 Christian Ehringfeld
#ifdef QT_DEBUG
#define DEFAULTMSGTYPE MsgType::DEBUG
40cf6a8c SebastianDiel
//#define DIFFABLEOUTPUT
f12670e9 Christian Ehringfeld
#else
#define DEFAULTMSGTYPE MsgType::CRITICAL
#endif

40cf6a8c SebastianDiel
66704054 Christian Ehringfeld
public:
f12670e9 Christian Ehringfeld
Logger(QString path = "", MsgType min = DEFAULTMSGTYPE);
45135a14 Christian Ehringfeld
~Logger();
100034b7 Christian Ehringfeld
QString defaultPath() const;

void lastError(const QSqlError &e);
66704054 Christian Ehringfeld
void lastError(const QSqlQuery &q, bool logQuery = false);
100034b7 Christian Ehringfeld
QString getPath();
void setPath(const QString &value);
f12670e9 Christian Ehringfeld
void logMsg(const QString &value, const MsgType type = MsgType::DEBUG);

MsgType getMinimum() const;
void setMinimum(const MsgType &value);
100034b7 Christian Ehringfeld
66704054 Christian Ehringfeld
protected:
100034b7 Christian Ehringfeld
QString generateLogMsg(const QSqlError &e) const;
66704054 Christian Ehringfeld
QString generateLogMsg(const QSqlQuery &q, bool withValues = true) const;
f12670e9 Christian Ehringfeld
bool shouldBeLogged(const MsgType &type) const;
void outputToConsole(const MsgType &type, const QString &msg) const;

100034b7 Christian Ehringfeld
66704054 Christian Ehringfeld
private:
100034b7 Christian Ehringfeld
QString path;
f12670e9 Christian Ehringfeld
MsgType minimum;
100034b7 Christian Ehringfeld
};
2b455197 Christian Ehringfeld
}
100034b7 Christian Ehringfeld
#endif // LOGGER_H