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
|
|
|
|
2014-04-25 01:45:20 +04:00
|
|
|
#include "utility.h"
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
namespace OCC {
|
2012-12-05 19:45:28 +04:00
|
|
|
|
|
|
|
struct Log{
|
|
|
|
typedef enum{
|
2014-11-10 00:34:07 +03:00
|
|
|
Occ,
|
2012-12-05 19:45:28 +04:00
|
|
|
CSync
|
|
|
|
} Source;
|
|
|
|
|
|
|
|
QDateTime timeStamp;
|
|
|
|
Source source;
|
|
|
|
QString message;
|
|
|
|
};
|
|
|
|
|
2014-04-25 01:45:20 +04:00
|
|
|
class OWNCLOUDSYNC_EXPORT Logger : public QObject
|
2012-12-05 19:45:28 +04:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-05-26 15:01:29 +04:00
|
|
|
|
2012-12-05 19:45:28 +04:00
|
|
|
void log(Log log);
|
2015-02-14 16:21:37 +03:00
|
|
|
void doLog(const QString &log);
|
2012-12-05 19:45:28 +04:00
|
|
|
|
|
|
|
static void csyncLog( const QString& message );
|
|
|
|
static void mirallLog( const QString& message );
|
|
|
|
|
|
|
|
const QList<Log>& logs() const {return _logs;}
|
|
|
|
|
|
|
|
static Logger* instance();
|
|
|
|
|
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();
|
|
|
|
|
2014-05-26 15:01:29 +04:00
|
|
|
private:
|
2012-12-05 19:45:28 +04:00
|
|
|
Logger(QObject* parent=0);
|
2014-05-26 15:01:29 +04:00
|
|
|
~Logger();
|
2012-12-05 19:45:28 +04:00
|
|
|
QList<Log> _logs;
|
|
|
|
bool _showTime;
|
|
|
|
bool _doLogging;
|
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
|
|
|
};
|
|
|
|
|
2014-11-10 00:34:07 +03:00
|
|
|
} // namespace OCC
|
2012-12-05 19:45:28 +04:00
|
|
|
|
|
|
|
#endif // LOGGER_H
|