FileLog.h 1016 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * This is the source code of tgnet library v. 1.1
  3. * It is licensed under GNU GPL v. 2 or later.
  4. * You should have received a copy of the license in this archive (see LICENSE).
  5. *
  6. * Copyright Nikolai Kudashov, 2015-2018.
  7. */
  8. #ifndef FILELOG_H
  9. #define FILELOG_H
  10. #include "Defines.h"
  11. class FileLog {
  12. public:
  13. FileLog();
  14. void init(std::string path);
  15. static void fatal(const char *message, ...) __attribute__((format (printf, 1, 2)));
  16. static void e(const char *message, ...) __attribute__((format (printf, 1, 2)));
  17. static void w(const char *message, ...) __attribute__((format (printf, 1, 2)));
  18. static void d(const char *message, ...) __attribute__((format (printf, 1, 2)));
  19. static FileLog &getInstance();
  20. private:
  21. FILE *logFile = nullptr;
  22. pthread_mutex_t mutex;
  23. };
  24. extern bool LOGS_ENABLED;
  25. #define DEBUG_FATAL FileLog::getInstance().fatal
  26. #define DEBUG_E FileLog::getInstance().e
  27. #define DEBUG_W FileLog::getInstance().w
  28. #define DEBUG_D FileLog::getInstance().d
  29. #endif