logger.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #ifndef LOGGER_H
  15. #define LOGGER_H
  16. #include <QObject>
  17. #include <QList>
  18. #include <QDateTime>
  19. #include <QFile>
  20. #include <QTextStream>
  21. #include <qmutex.h>
  22. #include "utility.h"
  23. namespace OCC {
  24. struct Log{
  25. typedef enum{
  26. Occ,
  27. CSync
  28. } Source;
  29. QDateTime timeStamp;
  30. Source source;
  31. QString message;
  32. };
  33. /**
  34. * @brief The Logger class
  35. * @ingroup libsync
  36. */
  37. class OWNCLOUDSYNC_EXPORT Logger : public QObject
  38. {
  39. Q_OBJECT
  40. public:
  41. bool isNoop() const;
  42. void log(Log log);
  43. void doLog(const QString &log);
  44. static void mirallLog( const QString& message );
  45. const QList<Log>& logs() const {return _logs;}
  46. static Logger* instance();
  47. void postGuiLog(const QString& title, const QString& message);
  48. void postOptionalGuiLog(const QString& title, const QString& message);
  49. void postGuiMessage(const QString& title, const QString& message);
  50. void setLogWindowActivated(bool activated);
  51. void setLogFile( const QString & name );
  52. void setLogExpire( int expire );
  53. void setLogDir( const QString& dir );
  54. void setLogFlush( bool flush );
  55. signals:
  56. void logWindowLog(const QString&);
  57. void guiLog(const QString&, const QString&);
  58. void guiMessage(const QString&, const QString&);
  59. void optionalGuiLog(const QString&, const QString&);
  60. public slots:
  61. void enterNextLogFile();
  62. private:
  63. Logger(QObject* parent=0);
  64. ~Logger();
  65. QList<Log> _logs;
  66. bool _showTime;
  67. bool _logWindowActivated;
  68. QFile _logFile;
  69. bool _doFileFlush;
  70. int _logExpire;
  71. QScopedPointer<QTextStream> _logstream;
  72. QMutex _mutex;
  73. QString _logDirectory;
  74. };
  75. } // namespace OCC
  76. #endif // LOGGER_H