]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Copyright The OpenTelemetry Authors |
2 | // SPDX-License-Identifier: Apache-2.0/ | |
3 | ||
4 | #pragma once | |
5 | #ifdef ENABLE_LOGS_PREVIEW | |
6 | ||
7 | # include <memory> | |
8 | # include <mutex> | |
9 | # include <string> | |
10 | # include <vector> | |
11 | ||
12 | # include "opentelemetry/logs/logger_provider.h" | |
13 | # include "opentelemetry/logs/noop.h" | |
14 | # include "opentelemetry/nostd/shared_ptr.h" | |
15 | # include "opentelemetry/sdk/common/atomic_shared_ptr.h" | |
16 | # include "opentelemetry/sdk/logs/logger.h" | |
17 | # include "opentelemetry/sdk/logs/logger_context.h" | |
18 | # include "opentelemetry/sdk/logs/processor.h" | |
19 | ||
20 | // Define the maximum number of loggers that are allowed to be registered to the loggerprovider. | |
21 | // TODO: Add link to logging spec once this is added to it | |
22 | # define MAX_LOGGER_COUNT 100 | |
23 | ||
24 | OPENTELEMETRY_BEGIN_NAMESPACE | |
25 | namespace sdk | |
26 | { | |
27 | namespace logs | |
28 | { | |
29 | class Logger; | |
30 | ||
31 | class LoggerProvider final : public opentelemetry::logs::LoggerProvider | |
32 | { | |
33 | public: | |
34 | /** | |
35 | * Initialize a new logger provider | |
36 | * @param processor The span processor for this logger provider. This must | |
37 | * not be a nullptr. | |
38 | * @param resource The resources for this logger provider. | |
39 | * @param sampler The sampler for this logger provider. This must | |
40 | * not be a nullptr. | |
41 | * @param id_generator The custom id generator for this logger provider. This must | |
42 | * not be a nullptr | |
43 | */ | |
44 | explicit LoggerProvider(std::unique_ptr<LogProcessor> &&processor, | |
45 | opentelemetry::sdk::resource::Resource resource = | |
46 | opentelemetry::sdk::resource::Resource::Create({})) noexcept; | |
47 | ||
48 | explicit LoggerProvider(std::vector<std::unique_ptr<LogProcessor>> &&processors, | |
49 | opentelemetry::sdk::resource::Resource resource = | |
50 | opentelemetry::sdk::resource::Resource::Create({})) noexcept; | |
51 | ||
52 | /** | |
53 | * Initialize a new logger provider. A processor must later be assigned | |
54 | * to this logger provider via the AddProcessor() method. | |
55 | */ | |
56 | explicit LoggerProvider() noexcept; | |
57 | ||
58 | /** | |
59 | * Initialize a new logger provider with a specified context | |
60 | * @param context The shared logger configuration/pipeline for this provider. | |
61 | */ | |
62 | explicit LoggerProvider(std::shared_ptr<sdk::logs::LoggerContext> context) noexcept; | |
63 | ||
64 | ~LoggerProvider(); | |
65 | ||
66 | /** | |
67 | * Creates a logger with the given name, and returns a shared pointer to it. | |
68 | * If a logger with that name already exists, return a shared pointer to it | |
69 | * @param logger_name The name of the logger to be created. | |
70 | * @param options The options for the logger. TODO: Once the logging spec defines it, | |
71 | * give a list of options that the logger supports. | |
72 | * @param library_name The version of the library. | |
73 | * @param library_version The version of the library. | |
74 | * @param schema_url The schema URL. | |
75 | */ | |
76 | nostd::shared_ptr<opentelemetry::logs::Logger> GetLogger( | |
77 | nostd::string_view logger_name, | |
78 | nostd::string_view options, | |
79 | nostd::string_view library_name, | |
80 | nostd::string_view library_version = "", | |
81 | nostd::string_view schema_url = "") noexcept override; | |
82 | /** | |
83 | * Creates a logger with the given name, and returns a shared pointer to it. | |
84 | * If a logger with that name already exists, return a shared pointer to it | |
85 | * @param name The name of the logger to be created. | |
86 | * @param args The arguments for the logger. TODO: Once the logging spec defines it, | |
87 | * give a list of arguments that the logger supports. | |
88 | * @param library_name The version of the library. | |
89 | * @param library_version The version of the library. | |
90 | * @param schema_url The schema URL. | |
91 | */ | |
92 | nostd::shared_ptr<opentelemetry::logs::Logger> GetLogger( | |
93 | nostd::string_view logger_name, | |
94 | nostd::span<nostd::string_view> args, | |
95 | nostd::string_view library_name, | |
96 | nostd::string_view library_version = "", | |
97 | nostd::string_view schema_url = "") noexcept override; | |
98 | ||
99 | /** | |
100 | * Add the processor that is stored internally in the logger provider. | |
101 | * @param processor The processor to be stored inside the logger provider. | |
102 | * This must not be a nullptr. | |
103 | */ | |
104 | void AddProcessor(std::unique_ptr<LogProcessor> processor) noexcept; | |
105 | ||
106 | /** | |
107 | * Obtain the resource associated with this logger provider. | |
108 | * @return The resource for this logger provider. | |
109 | */ | |
110 | const opentelemetry::sdk::resource::Resource &GetResource() const noexcept; | |
111 | ||
112 | /** | |
113 | * Shutdown the log processor associated with this log provider. | |
114 | */ | |
115 | bool Shutdown() noexcept; | |
116 | ||
117 | /** | |
118 | * Force flush the log processor associated with this log provider. | |
119 | */ | |
120 | bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept; | |
121 | ||
122 | private: | |
123 | // order of declaration is important here - loggers should destroy only after context. | |
124 | std::vector<std::shared_ptr<opentelemetry::sdk::logs::Logger>> loggers_; | |
125 | std::shared_ptr<sdk::logs::LoggerContext> context_; | |
126 | std::mutex lock_; | |
127 | }; | |
128 | } // namespace logs | |
129 | } // namespace sdk | |
130 | OPENTELEMETRY_END_NAMESPACE | |
131 | #endif |