logger.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2015 MongoDB Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <memory>
  16. #include <bsoncxx/stdx/string_view.hpp>
  17. #include <mongocxx/stdx.hpp>
  18. #include <mongocxx/config/prelude.hpp>
  19. namespace mongocxx {
  20. MONGOCXX_INLINE_NAMESPACE_BEGIN
  21. ///
  22. /// The log level of a message passed to a mongocxx::logger.
  23. ///
  24. enum class log_level {
  25. k_error,
  26. k_critical,
  27. k_warning,
  28. k_message,
  29. k_info,
  30. k_debug,
  31. k_trace,
  32. };
  33. ///
  34. /// Returns a stringification of the given log level.
  35. ///
  36. /// @param level
  37. /// The type to stringify.
  38. ///
  39. /// @return a std::string representation of the type.
  40. ///
  41. MONGOCXX_API stdx::string_view MONGOCXX_CALL to_string(log_level level);
  42. ///
  43. /// The interface that all user-defined loggers must implement.
  44. ///
  45. class MONGOCXX_API logger {
  46. public:
  47. virtual ~logger();
  48. ///
  49. /// Handles a log message. User defined logger implementations may do whatever they wish when
  50. /// this is called, such as log the output to a file or send it to a remote server for analysis.
  51. ///
  52. /// @param level
  53. /// The log level of the current log message
  54. /// @param domain
  55. /// The domain of the current log message, such as 'client'
  56. /// @param message
  57. /// The text of the current log message.
  58. virtual void operator()(log_level level,
  59. stdx::string_view domain,
  60. stdx::string_view message) noexcept = 0;
  61. protected:
  62. ///
  63. /// Default constructor
  64. ///
  65. logger();
  66. };
  67. MONGOCXX_INLINE_NAMESPACE_END
  68. } // namespace mongocxx
  69. #include <mongocxx/config/postlude.hpp>