log.h 557 B

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