logger_impl.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #ifdef WINDOWS_BUILD
  3. #ifdef LOGGER_EXPORTS
  4. #define LOGGER_API _declspec(dllexport)
  5. #else
  6. #define LOGGER_API _declspec(dllimport)
  7. #endif
  8. #elif LINUX_BUILD
  9. #define LOGGER_API
  10. #endif
  11. //stl
  12. #include <iostream>
  13. #include <mutex>
  14. #include <deque>
  15. //boost
  16. #include <asio.hpp>
  17. //robotics
  18. #include "../robot/robotics/datetime.hpp"
  19. #include "../robot/robotics/text_stream.hpp"
  20. #include "../robot/robotics/config.hpp"
  21. namespace robotics::v3 {
  22. class LOGGER_API logger_impl {
  23. public:
  24. ~logger_impl();
  25. void write(int color, std::string const& type, std::string const& time, std::string const& file, std::string const& func, int line, std::thread::id thread_id, std::string const& text);
  26. static logger_impl& instance();
  27. static void install(std::string const& filename = "./config/config.ini");
  28. private:
  29. explicit logger_impl();
  30. void backup(std::string const& filename);
  31. void remove();
  32. private:
  33. int max_time_ = 30;
  34. int max_size_ = 10;
  35. std::set<std::string> save_;
  36. asio::thread_pool thread_pool_;
  37. };
  38. class LOGGER_API logger_stream {
  39. public:
  40. explicit logger_stream(int color, std::string const& type, std::string const& time, std::string const& file, std::string const& func, int line, std::thread::id thread_id);
  41. ~logger_stream();
  42. text_stream stream;
  43. private:
  44. std::string type_;
  45. std::string time_;
  46. std::string file_;
  47. std::string func_;
  48. int line_ = 0;
  49. int color_ = 37;
  50. std::thread::id thread_id_;
  51. };
  52. }