log.h 631 B

1234567891011121314151617181920212223242526272829303132
  1. #ifndef AVPLAYER2_LOG_H
  2. #define AVPLAYER2_LOG_H
  3. #pragma once
  4. #include <QFile>
  5. #include <QFileInfo>
  6. #include <QTextStream>
  7. #include <QTime>
  8. #include <QtDebug>
  9. #include <memory>
  10. void logOutput(const QtMsgType type, const QMessageLogContext& context, const QString& msg);
  11. class Logger
  12. {
  13. public:
  14. static Logger& instance()
  15. {
  16. static Logger instance;
  17. return instance;
  18. }
  19. void log(const QString& str);
  20. private:
  21. explicit Logger(const QString& file = "log.txt");
  22. virtual ~Logger();
  23. private:
  24. std::unique_ptr<QFile> m_logfile;
  25. std::unique_ptr<QTextStream> m_ts;
  26. };
  27. #endif // AVPLAYER2_LOG_H