logger_impl.h 1.5 KB

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