2012-12-05 19:45:28 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
*
|
|
|
|
* 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 2 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LOGGER_H
|
|
|
|
#define LOGGER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QList>
|
|
|
|
#include <QDateTime>
|
2013-10-02 17:28:33 +04:00
|
|
|
#include <QFile>
|
|
|
|
#include <QTextStream>
|
2013-10-03 16:21:45 +04:00
|
|
|
#include <qmutex.h>
|
2012-12-05 19:45:28 +04:00
|
|
|
|
|
|
|
namespace Mirall {
|
|
|
|
|
|
|
|
struct Log{
|
|
|
|
typedef enum{
|
|
|
|
Mirall,
|
|
|
|
CSync
|
|
|
|
} Source;
|
|
|
|
|
|
|
|
QDateTime timeStamp;
|
|
|
|
Source source;
|
|
|
|
QString message;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Logger : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
void log(Log log);
|
|
|
|
|
|
|
|
static void csyncLog( const QString& message );
|
|
|
|
static void mirallLog( const QString& message );
|
|
|
|
|
|
|
|
const QList<Log>& logs() const {return _logs;}
|
|
|
|
|
|
|
|
static Logger* instance();
|
|
|
|
static void destroy();
|
|
|
|
|
2013-08-07 16:58:56 +04:00
|
|
|
void postGuiLog(const QString& title, const QString& message);
|
|
|
|
void postOptionalGuiLog(const QString& title, const QString& message);
|
|
|
|
void postGuiMessage(const QString& title, const QString& message);
|
|
|
|
|
2013-10-02 17:28:33 +04:00
|
|
|
void setLogFile( const QString & name );
|
|
|
|
void setLogExpire( int expire );
|
|
|
|
void setLogDir( const QString& dir );
|
|
|
|
void setLogFlush( bool flush );
|
2013-10-02 17:55:15 +04:00
|
|
|
|
2012-12-05 19:45:28 +04:00
|
|
|
signals:
|
|
|
|
void newLog(const QString&);
|
2012-12-11 15:49:48 +04:00
|
|
|
void guiLog(const QString&, const QString&);
|
2013-08-07 16:58:56 +04:00
|
|
|
void guiMessage(const QString&, const QString&);
|
2013-07-05 03:01:23 +04:00
|
|
|
void optionalGuiLog(const QString&, const QString&);
|
2012-12-05 19:45:28 +04:00
|
|
|
|
2013-10-02 17:28:33 +04:00
|
|
|
public slots:
|
|
|
|
void enterNextLogFile();
|
|
|
|
|
2012-12-05 19:45:28 +04:00
|
|
|
protected:
|
|
|
|
Logger(QObject* parent=0);
|
|
|
|
QList<Log> _logs;
|
|
|
|
bool _showTime;
|
|
|
|
bool _doLogging;
|
|
|
|
|
|
|
|
static Logger* _instance;
|
2013-10-02 17:28:33 +04:00
|
|
|
|
|
|
|
QFile _logFile;
|
|
|
|
bool _doFileFlush;
|
|
|
|
int _logExpire;
|
|
|
|
QScopedPointer<QTextStream> _logstream;
|
2013-10-03 16:21:45 +04:00
|
|
|
QMutex _mutex;
|
2013-10-02 17:28:33 +04:00
|
|
|
QString _logDirectory;
|
|
|
|
|
2012-12-05 19:45:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Mirall
|
|
|
|
|
|
|
|
#endif // LOGGER_H
|