logger.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // logger.hpp
  3. // logger
  4. //
  5. // Created by Sam Jaffe on 9/3/16.
  6. //
  7. #pragma once
  8. //
  9. // Logger.hpp
  10. // DanmakuRPG
  11. //
  12. // Created by Sam Jaffe on 7/18/15.
  13. // Copyright (c) 2015 Sam Jaffe. All rights reserved.
  14. //
  15. #pragma once
  16. #include <cstdarg>
  17. #include <cstdlib>
  18. #include <cstring>
  19. #include <memory>
  20. #include <string>
  21. #include "message.h"
  22. #define log_message(logger, lvl, ...) \
  23. logger.log(level::lvl, log_here, __VA_ARGS__)
  24. namespace logging {
  25. enum class level : int;
  26. struct location_info;
  27. class logger_impl;
  28. struct logpacket;
  29. class logger {
  30. private:
  31. friend class manager;
  32. std::string const logger_name_;
  33. std::shared_ptr<logger_impl> impl_;
  34. public:
  35. ~logger();
  36. template <typename... Args>
  37. inline void log(level ll, std::string const & interp, Args &&... args) {
  38. log(ll, message(interp, std::forward<Args>(args)...));
  39. }
  40. template <typename... Args>
  41. inline void log(level ll, location_info const & info,
  42. std::string const & interp, Args &&... args) {
  43. log(ll, info, message(interp, std::forward<Args>(args)...));
  44. }
  45. void log(level ll, message const &);
  46. void flush();
  47. protected:
  48. logger(std::string const & name, std::shared_ptr<logger_impl> impl);
  49. private:
  50. void log(level ll, location_info const & info, message const &);
  51. };
  52. }