You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.2 KiB

1 year ago
  1. #pragma once
  2. #include "logging_api.h"
  3. #include "fmt/format.h"
  4. #include "fmt/ostream.h"
  5. namespace vlc
  6. {
  7. namespace logging
  8. {
  9. #ifndef VLC_CUSTOM_DEFAULT_LOGGING_TAG
  10. static const char* default_logging_tag = "visionlabs";
  11. #endif
  12. struct Tag
  13. {
  14. const char* name = default_logging_tag;
  15. Tag() = default;
  16. explicit Tag(const char* tagname) : name(tagname)
  17. {
  18. }
  19. };
  20. void write(Severity severity, const std::string& message, const char* tag = default_logging_tag);
  21. inline void error(const std::string& message, const char* tag = default_logging_tag)
  22. {
  23. #if VLC_LOGGING_MIN_LEVEL <= 3
  24. write(Severity::Error, message, tag);
  25. #endif
  26. }
  27. inline void warning(const std::string& message, const char* tag = default_logging_tag)
  28. {
  29. #if VLC_LOGGING_MIN_LEVEL <= 2
  30. write(Severity::Warning, message, tag);
  31. #endif
  32. }
  33. inline void info(const std::string& message, const char* tag = default_logging_tag)
  34. {
  35. #if VLC_LOGGING_MIN_LEVEL <= 1
  36. write(Severity::Information, message, tag);
  37. #endif
  38. }
  39. inline void debug(const std::string& message, const char* tag = default_logging_tag)
  40. {
  41. #if VLC_LOGGING_MIN_LEVEL <= 0
  42. write(Severity::Debug, message, tag);
  43. #endif
  44. }
  45. template<typename... Args> void error(const char* format, Args... args)
  46. {
  47. auto message = fmt::format(format, std::forward<Args>(args)...);
  48. error(message);
  49. }
  50. template<typename... Args> void warning(const char* format, Args... args)
  51. {
  52. auto message = fmt::format(format, std::forward<Args>(args)...);
  53. warning(message);
  54. }
  55. template<typename... Args> void info(const char* format, Args... args)
  56. {
  57. auto message = fmt::format(format, std::forward<Args>(args)...);
  58. info(message);
  59. }
  60. template<typename... Args> void debug(const char* format, Args... args)
  61. {
  62. auto message = fmt::format(format, std::forward<Args>(args)...);
  63. debug(message);
  64. }
  65. template<typename... Args> void error(Tag&& tag, const char* format, Args... args)
  66. {
  67. auto message = fmt::format(format, std::forward<Args>(args)...);
  68. error(message, tag.name);
  69. }
  70. template<typename... Args> void warning(Tag&& tag, const char* format, Args... args)
  71. {
  72. auto message = fmt::format(format, std::forward<Args>(args)...);
  73. warning(message, tag.name);
  74. }
  75. template<typename... Args> void info(Tag&& tag, const char* format, Args... args)
  76. {
  77. auto message = fmt::format(format, std::forward<Args>(args)...);
  78. info(message, tag.name);
  79. }
  80. template<typename... Args> void debug(Tag&& tag, const char* format, Args... args)
  81. {
  82. auto message = fmt::format(format, std::forward<Args>(args)...);
  83. debug(message, tag.name);
  84. }
  85. template<typename... Args> void error(const char* tag, const char* format, Args... args)
  86. {
  87. error(Tag(tag), format, std::forward<Args>(args)...);
  88. }
  89. template<typename... Args> void warning(const char* tag, const char* format, Args... args)
  90. {
  91. warning(Tag(tag), format, std::forward<Args>(args)...);
  92. }
  93. template<typename... Args> void info(const char* tag, const char* format, Args... args)
  94. {
  95. info(Tag(tag), format, std::forward<Args>(args)...);
  96. }
  97. template<typename... Args> void debug(const char* tag, const char* format, Args... args)
  98. {
  99. debug(Tag(tag), format, std::forward<Args>(args)...);
  100. }
  101. }
  102. }