logger.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "logger_fwd.h"
  22. #include "format.h"
  23. #define log_message( logger, lvl, ... ) \
  24. logger.log(level::lvl, log_here, __VA_ARGS__)
  25. namespace logging {
  26. class logger_impl;
  27. class manager;
  28. class logger {
  29. public:
  30. ~logger();
  31. template <typename... Args>
  32. inline void log(level ll, std::string const & interp, Args && ...args) {
  33. log(ll, location_info{}, interp, std::forward<Args>(args)...);
  34. }
  35. template <typename... Args>
  36. inline void log(level ll, location_info info,
  37. std::string const & interp, Args && ...args) {
  38. log(ll, info, message(interp, std::forward<Args>(args)...));
  39. }
  40. void flush();
  41. protected:
  42. logger(std::string const & name, std::shared_ptr<logger_impl> impl);
  43. private:
  44. friend class manager;
  45. void log(level ll, location_info info, message const&);
  46. private:
  47. std::string const logger_name_;
  48. std::shared_ptr<logger_impl> impl_;
  49. };
  50. }