1/*
2 * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15#ifndef LOGGER_H
16#define LOGGER_H
17
18#include <QObject>
19#include <QList>
20#include <QDateTime>
21#include <QFile>
22#include <QTextStream>
23#include <qmutex.h>
24
25#include "common/utility.h"
26#include "logger.h"
27#include "owncloudlib.h"
28
29namespace OCC {
30
31struct Log
32{
33 QDateTime timeStamp;
34 QString message;
35};
36
37/**
38 * @brief The Logger class
39 * @ingroup libsync
40 */
41class OWNCLOUDSYNC_EXPORT Logger : public QObject
42{
43 Q_OBJECT
44public:
45 bool isNoop() const;
46 bool isLoggingToFile() const;
47
48 void log(Log log);
49 void doLog(const QString &log);
50
51 static void mirallLog(const QString &message);
52
53 const QList<Log> &logs() const { return _logs; }
54
55 static Logger *instance();
56
57 void postGuiLog(const QString &title, const QString &message);
58 void postOptionalGuiLog(const QString &title, const QString &message);
59 void postGuiMessage(const QString &title, const QString &message);
60
61 void setLogWindowActivated(bool activated);
62 void setLogFile(const QString &name);
63 void setLogExpire(int expire);
64 void setLogDir(const QString &dir);
65 void setLogFlush(bool flush);
66
67 bool logDebug() const { return _logDebug; }
68 void setLogDebug(bool debug);
69
70 /** Returns where the automatic logdir would be */
71 QString temporaryFolderLogDirPath() const;
72
73 /** Sets up default dir log setup.
74 *
75 * logdir: a temporary folder
76 * logexpire: 4 hours
77 * logdebug: true
78 *
79 * Used in conjunction with ConfigFile::automaticLogDir
80 */
81 void setupTemporaryFolderLogDir();
82
83 /** For switching off via logwindow */
84 void disableTemporaryFolderLogDir();
85
86signals:
87 void logWindowLog(const QString &);
88
89 void guiLog(const QString &, const QString &);
90 void guiMessage(const QString &, const QString &);
91 void optionalGuiLog(const QString &, const QString &);
92
93public slots:
94 void enterNextLogFile();
95
96private:
97 Logger(QObject *parent = 0);
98 ~Logger();
99 QList<Log> _logs;
100 bool _showTime;
101 bool _logWindowActivated;
102 QFile _logFile;
103 bool _doFileFlush;
104 int _logExpire;
105 bool _logDebug;
106 QScopedPointer<QTextStream> _logstream;
107 mutable QMutex _mutex;
108 QString _logDirectory;
109 bool _temporaryFolderLogDir = false;
110};
111
112} // namespace OCC
113
114#endif // LOGGER_H
115