]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/api/include/opentelemetry/logs/logger.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / api / include / opentelemetry / logs / logger.h
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #pragma once
5 #ifdef ENABLE_LOGS_PREVIEW
6
7 # include <chrono>
8 # include <map>
9 # include <vector>
10
11 # include "opentelemetry/common/attribute_value.h"
12 # include "opentelemetry/common/key_value_iterable.h"
13 # include "opentelemetry/common/key_value_iterable_view.h"
14 # include "opentelemetry/common/macros.h"
15 # include "opentelemetry/common/timestamp.h"
16 # include "opentelemetry/logs/severity.h"
17 # include "opentelemetry/nostd/shared_ptr.h"
18 # include "opentelemetry/nostd/span.h"
19 # include "opentelemetry/nostd/string_view.h"
20 # include "opentelemetry/nostd/type_traits.h"
21 # include "opentelemetry/trace/span_id.h"
22 # include "opentelemetry/trace/trace_flags.h"
23 # include "opentelemetry/trace/trace_id.h"
24 # include "opentelemetry/version.h"
25
26 OPENTELEMETRY_BEGIN_NAMESPACE
27 namespace logs
28 {
29 /**
30 * Handles log record creation.
31 **/
32 class Logger
33 {
34 public:
35 virtual ~Logger() = default;
36
37 /* Returns the name of the logger */
38 virtual const nostd::string_view GetName() noexcept = 0;
39
40 /**
41 * Each of the following overloaded Log(...) methods
42 * creates a log message with the specific parameters passed.
43 *
44 * @param severity the severity level of the log event.
45 * @param message the string message of the log (perhaps support std::fmt or fmt-lib format).
46 * @param attributes the attributes, stored as a 2D list of key/value pairs, that are associated
47 * with the log event.
48 * @param trace_id the trace id associated with the log event.
49 * @param span_id the span id associate with the log event.
50 * @param trace_flags the trace flags associated with the log event.
51 * @param timestamp the timestamp the log record was created.
52 * @throws No exceptions under any circumstances.
53 */
54
55 /**
56 * The base Log(...) method that all other Log(...) overloaded methods will eventually call,
57 * in order to create a log record.
58 */
59 virtual void Log(Severity severity,
60 nostd::string_view body,
61 const common::KeyValueIterable &attributes,
62 trace::TraceId trace_id,
63 trace::SpanId span_id,
64 trace::TraceFlags trace_flags,
65 common::SystemTimestamp timestamp) noexcept = 0;
66
67 /**
68 * Each of the following overloaded Log(...) methods
69 * creates a log message with the specific parameters passed.
70 *
71 * @param severity the severity level of the log event.
72 * @param name the name of the log event.
73 * @param message the string message of the log (perhaps support std::fmt or fmt-lib format).
74 * @param attributes the attributes, stored as a 2D list of key/value pairs, that are associated
75 * with the log event.
76 * @param trace_id the trace id associated with the log event.
77 * @param span_id the span id associate with the log event.
78 * @param trace_flags the trace flags associated with the log event.
79 * @param timestamp the timestamp the log record was created.
80 * @throws No exceptions under any circumstances.
81 */
82 OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future")
83 virtual void Log(Severity severity,
84 OPENTELEMETRY_MAYBE_UNUSED nostd::string_view name,
85 nostd::string_view body,
86 const common::KeyValueIterable &attributes,
87 trace::TraceId trace_id,
88 trace::SpanId span_id,
89 trace::TraceFlags trace_flags,
90 common::SystemTimestamp timestamp) noexcept
91 {
92 Log(severity, body, attributes, trace_id, span_id, trace_flags, timestamp);
93 }
94
95 /*** Overloaded methods for KeyValueIterables ***/
96 /**
97 * The secondary base Log(...) method that all other Log(...) overloaded methods except the one
98 * above will eventually call, in order to create a log record.
99 */
100 template <class T,
101 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
102 void Log(Severity severity,
103 nostd::string_view body,
104 const T &attributes,
105 trace::TraceId trace_id,
106 trace::SpanId span_id,
107 trace::TraceFlags trace_flags,
108 common::SystemTimestamp timestamp) noexcept
109 {
110 Log(severity, body, common::KeyValueIterableView<T>(attributes), trace_id, span_id, trace_flags,
111 timestamp);
112 }
113
114 template <class T,
115 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
116 OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future")
117 void Log(Severity severity,
118 nostd::string_view name,
119 nostd::string_view body,
120 const T &attributes,
121 trace::TraceId trace_id,
122 trace::SpanId span_id,
123 trace::TraceFlags trace_flags,
124 common::SystemTimestamp timestamp) noexcept
125 {
126 Log(severity, name, body, common::KeyValueIterableView<T>(attributes), trace_id, span_id,
127 trace_flags, timestamp);
128 }
129
130 void Log(Severity severity,
131 nostd::string_view body,
132 std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
133 trace::TraceId trace_id,
134 trace::SpanId span_id,
135 trace::TraceFlags trace_flags,
136 common::SystemTimestamp timestamp) noexcept
137 {
138 return this->Log(severity, body,
139 nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
140 attributes.begin(), attributes.end()},
141 trace_id, span_id, trace_flags, timestamp);
142 }
143
144 OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future")
145 void Log(Severity severity,
146 nostd::string_view name,
147 nostd::string_view body,
148 std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>> attributes,
149 trace::TraceId trace_id,
150 trace::SpanId span_id,
151 trace::TraceFlags trace_flags,
152 common::SystemTimestamp timestamp) noexcept
153 {
154 return this->Log(severity, name, body,
155 nostd::span<const std::pair<nostd::string_view, common::AttributeValue>>{
156 attributes.begin(), attributes.end()},
157 trace_id, span_id, trace_flags, timestamp);
158 }
159
160 /** Wrapper methods that the user could call for convenience when logging **/
161
162 /**
163 * Writes a log.
164 * @param severity The severity of the log
165 * @param message The message to log
166 */
167 void Log(Severity severity, nostd::string_view message) noexcept
168 {
169 this->Log(severity, message, {}, {}, {}, {}, std::chrono::system_clock::now());
170 }
171
172 OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future")
173 void Log(Severity severity, nostd::string_view name, nostd::string_view message) noexcept
174 {
175 this->Log(severity, name, message, {}, {}, {}, {}, std::chrono::system_clock::now());
176 }
177
178 /**
179 * Writes a log.
180 * @param severity The severity of the log
181 * @param attributes The attributes of the log as a key/value object
182 */
183 template <class T,
184 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
185 void Log(Severity severity, const T &attributes) noexcept
186 {
187 this->Log(severity, "", attributes, {}, {}, {}, std::chrono::system_clock::now());
188 }
189
190 /**
191 * Writes a log.
192 * @param severity The severity of the log
193 * @param message The message to log
194 * @param attributes The attributes of the log as a key/value object
195 */
196 template <class T,
197 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
198 void Log(Severity severity, nostd::string_view message, const T &attributes) noexcept
199 {
200 this->Log(severity, message, attributes, {}, {}, {}, std::chrono::system_clock::now());
201 }
202
203 /**
204 * Writes a log.
205 * @param severity The severity of the log
206 * @param attributes The attributes of the log as an initializer list
207 */
208 void Log(Severity severity,
209 std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
210 attributes) noexcept
211 {
212 this->Log(severity, "", attributes, {}, {}, {}, std::chrono::system_clock::now());
213 }
214
215 /**
216 * Writes a log.
217 * @param severity The severity of the log
218 * @param message The message to log
219 * @param attributes The attributes of the log as an initializer list
220 */
221 void Log(Severity severity,
222 nostd::string_view message,
223 std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
224 attributes) noexcept
225 {
226 this->Log(severity, message, attributes, {}, {}, {}, std::chrono::system_clock::now());
227 }
228
229 /**
230 * Writes a log.
231 * @param severity The severity of the log
232 * @param attributes The attributes, stored as a 2D list of key/value pairs, that are associated
233 * with the log event
234 */
235 void Log(Severity severity, const common::KeyValueIterable &attributes) noexcept
236 {
237 this->Log(severity, "", attributes, {}, {}, {}, std::chrono::system_clock::now());
238 }
239
240 /**
241 * Writes a log.
242 * @param severity The severity of the log
243 * @param message The message to log
244 * @param attributes The attributes, stored as a 2D list of key/value pairs, that are associated
245 * with the log event
246 */
247 void Log(Severity severity,
248 nostd::string_view message,
249 const common::KeyValueIterable &attributes) noexcept
250 {
251 this->Log(severity, message, attributes, {}, {}, {}, std::chrono::system_clock::now());
252 }
253
254 /** Trace severity overloads **/
255
256 /**
257 * Writes a log with a severity of trace.
258 * @param message The message to log
259 */
260 void Trace(nostd::string_view message) noexcept { this->Log(Severity::kTrace, message); }
261
262 /**
263 * Writes a log with a severity of trace.
264 * @param name The name of the log
265 * @param message The message to log
266 */
267 OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future")
268 void Trace(nostd::string_view name, nostd::string_view message) noexcept
269 {
270 this->Log(Severity::kTrace, name, message);
271 }
272
273 /**
274 * Writes a log with a severity of trace.
275 * @param attributes The attributes of the log as a key/value object
276 */
277 template <class T,
278 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
279 void Trace(const T &attributes) noexcept
280 {
281 this->Log(Severity::kTrace, attributes);
282 }
283
284 /**
285 * Writes a log with a severity of trace.
286 * @param message The message of the log
287 * @param attributes The attributes of the log as a key/value object
288 */
289 template <class T,
290 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
291 void Trace(nostd::string_view message, const T &attributes) noexcept
292 {
293 this->Log(Severity::kTrace, message, attributes);
294 }
295
296 /**
297 * Writes a log with a severity of trace.
298 * @param attributes The attributes of the log as an initializer list
299 */
300 void Trace(std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
301 attributes) noexcept
302 {
303 this->Log(Severity::kTrace, attributes);
304 }
305
306 /**
307 * Writes a log with a severity of trace.
308 * @param message The message of the log
309 * @param attributes The attributes of the log as an initializer list
310 */
311 void Trace(nostd::string_view message,
312 std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
313 attributes) noexcept
314 {
315 this->Log(Severity::kTrace, message, attributes);
316 }
317
318 /** Debug severity overloads **/
319
320 /**
321 * Writes a log with a severity of debug.
322 * @param message The message to log
323 */
324 void Debug(nostd::string_view message) noexcept { this->Log(Severity::kDebug, message); }
325
326 /**
327 * Writes a log with a severity of debug.
328 * @param name The name of the log
329 * @param message The message to log
330 */
331 OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future")
332 void Debug(nostd::string_view name, nostd::string_view message) noexcept
333 {
334 this->Log(Severity::kDebug, name, message);
335 }
336
337 /**
338 * Writes a log with a severity of debug.
339 * @param attributes The attributes of the log as a key/value object
340 */
341 template <class T,
342 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
343 void Debug(const T &attributes) noexcept
344 {
345 this->Log(Severity::kDebug, attributes);
346 }
347
348 /**
349 * Writes a log with a severity of debug.
350 * @param message The message of the log
351 * @param attributes The attributes of the log as a key/value object
352 */
353 template <class T,
354 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
355 void Debug(nostd::string_view message, const T &attributes) noexcept
356 {
357 this->Log(Severity::kDebug, message, attributes);
358 }
359
360 /**
361 * Writes a log with a severity of debug.
362 * @param attributes The attributes of the log as an initializer list
363 */
364 void Debug(std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
365 attributes) noexcept
366 {
367 this->Log(Severity::kDebug, attributes);
368 }
369
370 /**
371 * Writes a log with a severity of debug.
372 * @param message The message of the log
373 * @param attributes The attributes of the log as an initializer list
374 */
375 void Debug(nostd::string_view message,
376 std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
377 attributes) noexcept
378 {
379 this->Log(Severity::kDebug, message, attributes);
380 }
381
382 /** Info severity overloads **/
383
384 /**
385 * Writes a log with a severity of info.
386 * @param message The message to log
387 */
388 void Info(nostd::string_view message) noexcept { this->Log(Severity::kInfo, message); }
389
390 /**
391 * Writes a log with a severity of info.
392 * @param name The name of the log
393 * @param message The message to log
394 */
395 OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future")
396 void Info(nostd::string_view name, nostd::string_view message) noexcept
397 {
398 this->Log(Severity::kInfo, name, message);
399 }
400
401 /**
402 * Writes a log with a severity of info.
403 * @param attributes The attributes of the log as a key/value object
404 */
405 template <class T,
406 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
407 void Info(const T &attributes) noexcept
408 {
409 this->Log(Severity::kInfo, attributes);
410 }
411
412 /**
413 * Writes a log with a severity of info.
414 * @param message The message of the log
415 * @param attributes The attributes of the log as a key/value object
416 */
417 template <class T,
418 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
419 void Info(nostd::string_view message, const T &attributes) noexcept
420 {
421 this->Log(Severity::kInfo, message, attributes);
422 }
423
424 /**
425 * Writes a log with a severity of info.
426 * @param attributes The attributes of the log as an initializer list
427 */
428 void Info(std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
429 attributes) noexcept
430 {
431 this->Log(Severity::kInfo, attributes);
432 }
433
434 /**
435 * Writes a log with a severity of info.
436 * @param message The message of the log
437 * @param attributes The attributes of the log as an initializer list
438 */
439 void Info(nostd::string_view message,
440 std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
441 attributes) noexcept
442 {
443 this->Log(Severity::kInfo, message, attributes);
444 }
445
446 /** Warn severity overloads **/
447
448 /**
449 * Writes a log with a severity of warn.
450 * @param message The message to log
451 */
452 void Warn(nostd::string_view message) noexcept { this->Log(Severity::kWarn, message); }
453
454 /**
455 * Writes a log with a severity of warn.
456 * @param name The name of the log
457 * @param message The message to log
458 */
459 OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future")
460 void Warn(nostd::string_view name, nostd::string_view message) noexcept
461 {
462 this->Log(Severity::kWarn, name, message);
463 }
464
465 /**
466 * Writes a log with a severity of warn.
467 * @param attributes The attributes of the log as a key/value object
468 */
469 template <class T,
470 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
471 void Warn(const T &attributes) noexcept
472 {
473 this->Log(Severity::kWarn, attributes);
474 }
475
476 /**
477 * Writes a log with a severity of warn.
478 * @param message The message of the log
479 * @param attributes The attributes of the log as a key/value object
480 */
481 template <class T,
482 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
483 void Warn(nostd::string_view message, const T &attributes) noexcept
484 {
485 this->Log(Severity::kWarn, message, attributes);
486 }
487
488 /**
489 * Writes a log with a severity of warn.
490 * @param attributes The attributes of the log as an initializer list
491 */
492 void Warn(std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
493 attributes) noexcept
494 {
495 this->Log(Severity::kWarn, attributes);
496 }
497
498 /**
499 * Writes a log with a severity of warn.
500 * @param message The message of the log
501 * @param attributes The attributes of the log as an initializer list
502 */
503 void Warn(nostd::string_view message,
504 std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
505 attributes) noexcept
506 {
507 this->Log(Severity::kWarn, message, attributes);
508 }
509
510 /** Error severity overloads **/
511
512 /**
513 * Writes a log with a severity of error.
514 * @param message The message to log
515 */
516 void Error(nostd::string_view message) noexcept { this->Log(Severity::kError, message); }
517
518 /**
519 * Writes a log with a severity of error.
520 * @param name The name of the log
521 * @param message The message to log
522 */
523 OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future")
524 void Error(nostd::string_view name, nostd::string_view message) noexcept
525 {
526 this->Log(Severity::kError, name, message);
527 }
528
529 /**
530 * Writes a log with a severity of error.
531 * @param attributes The attributes of the log as a key/value object
532 */
533 template <class T,
534 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
535 void Error(const T &attributes) noexcept
536 {
537 this->Log(Severity::kError, attributes);
538 }
539
540 /**
541 * Writes a log with a severity of error.
542 * @param message The message of the log
543 * @param attributes The attributes of the log as a key/value object
544 */
545 template <class T,
546 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
547 void Error(nostd::string_view message, const T &attributes) noexcept
548 {
549 this->Log(Severity::kError, message, attributes);
550 }
551
552 /**
553 * Writes a log with a severity of error.
554 * @param attributes The attributes of the log as an initializer list
555 */
556 void Error(std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
557 attributes) noexcept
558 {
559 this->Log(Severity::kError, attributes);
560 }
561
562 /**
563 * Writes a log with a severity of error.
564 * @param message The message of the log
565 * @param attributes The attributes of the log as an initializer list
566 */
567 void Error(nostd::string_view message,
568 std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
569 attributes) noexcept
570 {
571 this->Log(Severity::kError, message, attributes);
572 }
573
574 /** Fatal severity overloads **/
575
576 /**
577 * Writes a log with a severity of fatal.
578 * @param message The message to log
579 */
580 void Fatal(nostd::string_view message) noexcept { this->Log(Severity::kFatal, message); }
581
582 /**
583 * Writes a log with a severity of fatal.
584 * @param name The name of the log
585 * @param message The message to log
586 */
587 OPENTELEMETRY_DEPRECATED_MESSAGE("name will be removed in the future")
588 void Fatal(nostd::string_view name, nostd::string_view message) noexcept
589 {
590 this->Log(Severity::kFatal, name, message);
591 }
592
593 /**
594 * Writes a log with a severity of fatal.
595 * @param attributes The attributes of the log as a key/value object
596 */
597 template <class T,
598 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
599 void Fatal(const T &attributes) noexcept
600 {
601 this->Log(Severity::kFatal, attributes);
602 }
603
604 /**
605 * Writes a log with a severity of fatal.
606 * @param message The message of the log
607 * @param attributes The attributes of the log as a key/value object
608 */
609 template <class T,
610 nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
611 void Fatal(nostd::string_view message, const T &attributes) noexcept
612 {
613 this->Log(Severity::kFatal, message, attributes);
614 }
615
616 /**
617 * Writes a log with a severity of fatal.
618 * @param attributes The attributes of the log as an initializer list
619 */
620 void Fatal(std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
621 attributes) noexcept
622 {
623 this->Log(Severity::kFatal, attributes);
624 }
625
626 /**
627 * Writes a log with a severity of fatal.
628 * @param message The message of the log
629 * @param attributes The attributes of the log as an initializer list
630 */
631 void Fatal(nostd::string_view message,
632 std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
633 attributes) noexcept
634 {
635 this->Log(Severity::kFatal, message, attributes);
636 }
637 };
638 } // namespace logs
639 OPENTELEMETRY_END_NAMESPACE
640
641 #endif