logger_provider.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "opentelemetry/common/key_value_iterable.h"
  5. #include "opentelemetry/common/key_value_iterable_view.h"
  6. #include "opentelemetry/nostd/shared_ptr.h"
  7. #include "opentelemetry/nostd/span.h"
  8. #include "opentelemetry/nostd/string_view.h"
  9. #include "opentelemetry/nostd/type_traits.h"
  10. #include "opentelemetry/version.h"
  11. OPENTELEMETRY_BEGIN_NAMESPACE
  12. namespace logs
  13. {
  14. class Logger;
  15. /**
  16. * Creates new Logger instances.
  17. */
  18. class OPENTELEMETRY_EXPORT LoggerProvider
  19. {
  20. public:
  21. virtual ~LoggerProvider() = default;
  22. /**
  23. * Gets or creates a named Logger instance.
  24. *
  25. * Optionally a version can be passed to create a named and versioned Logger
  26. * instance.
  27. *
  28. * Optionally a configuration file name can be passed to create a configuration for
  29. * the Logger instance.
  30. *
  31. */
  32. virtual nostd::shared_ptr<Logger> GetLogger(
  33. nostd::string_view logger_name,
  34. nostd::string_view library_name = "",
  35. nostd::string_view library_version = "",
  36. nostd::string_view schema_url = "",
  37. const common::KeyValueIterable &attributes = common::NoopKeyValueIterable()) = 0;
  38. nostd::shared_ptr<Logger> GetLogger(
  39. nostd::string_view logger_name,
  40. nostd::string_view library_name,
  41. nostd::string_view library_version,
  42. nostd::string_view schema_url,
  43. std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes)
  44. {
  45. return GetLogger(logger_name, library_name, library_version, schema_url,
  46. nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
  47. attributes.begin(), attributes.end()});
  48. }
  49. template <class T,
  50. nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
  51. nostd::shared_ptr<Logger> GetLogger(nostd::string_view logger_name,
  52. nostd::string_view library_name,
  53. nostd::string_view library_version,
  54. nostd::string_view schema_url,
  55. const T &attributes)
  56. {
  57. return GetLogger(logger_name, library_name, library_version, schema_url,
  58. common::KeyValueIterableView<T>(attributes));
  59. }
  60. };
  61. } // namespace logs
  62. OPENTELEMETRY_END_NAMESPACE