NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/includes/opentelemetry/logs/logger.h
Go to the documentation of this file.
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include "opentelemetry/logs/logger_type_traits.h"
7 #include "opentelemetry/logs/severity.h"
8 #include "opentelemetry/nostd/string_view.h"
9 #include "opentelemetry/nostd/unique_ptr.h"
10 #include "opentelemetry/version.h"
11 
13 namespace common
14 {
15 class KeyValueIterable;
16 } // namespace common
17 
18 namespace logs
19 {
20 
21 class EventId;
22 class LogRecord;
23 
27 class Logger
28 {
29 public:
30  virtual ~Logger() = default;
31 
32  /* Returns the name of the logger */
33  virtual const nostd::string_view GetName() noexcept = 0;
34 
40  virtual nostd::unique_ptr<LogRecord> CreateLogRecord() noexcept = 0;
41 
47  virtual void EmitLogRecord(nostd::unique_ptr<LogRecord> &&log_record) noexcept = 0;
48 
67  template <class... ArgumentType>
68  void EmitLogRecord(nostd::unique_ptr<LogRecord> &&log_record, ArgumentType &&...args)
69  {
70  if (!log_record)
71  {
72  return;
73  }
74 
75  //
76  // Keep the parameter pack unpacking order from left to right because left
77  // ones are usually more important like severity and event_id than the
78  // attributes. The left to right unpack order could pass the more important
79  // data to processors to avoid caching and memory allocating.
80  //
81 #if __cplusplus <= 201402L
82  // C++14 does not support fold expressions for parameter pack expansion.
84  log_record.get(), std::forward<ArgumentType>(args)),
85  0)...};
86  IgnoreTraitResult(dummy);
87 #else
88  IgnoreTraitResult((detail::LogRecordSetterTrait<typename std::decay<ArgumentType>::type>::Set(
89  log_record.get(), std::forward<ArgumentType>(args)),
90  ...));
91 #endif
92 
93  EmitLogRecord(std::move(log_record));
94  }
95 
113  template <class... ArgumentType>
114  void EmitLogRecord(ArgumentType &&...args)
115  {
117 
118  EmitLogRecord(std::move(log_record), std::forward<ArgumentType>(args)...);
119  }
120 
136  template <class... ArgumentType>
137  void Trace(ArgumentType &&...args) noexcept
138  {
139  static_assert(
140  !detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
141  "Severity is already set.");
142  this->EmitLogRecord(Severity::kTrace, std::forward<ArgumentType>(args)...);
143  }
144 
160  template <class... ArgumentType>
161  void Debug(ArgumentType &&...args) noexcept
162  {
163  static_assert(
164  !detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
165  "Severity is already set.");
166  this->EmitLogRecord(Severity::kDebug, std::forward<ArgumentType>(args)...);
167  }
168 
184  template <class... ArgumentType>
185  void Info(ArgumentType &&...args) noexcept
186  {
187  static_assert(
188  !detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
189  "Severity is already set.");
190  this->EmitLogRecord(Severity::kInfo, std::forward<ArgumentType>(args)...);
191  }
192 
208  template <class... ArgumentType>
209  void Warn(ArgumentType &&...args) noexcept
210  {
211  static_assert(
212  !detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
213  "Severity is already set.");
214  this->EmitLogRecord(Severity::kWarn, std::forward<ArgumentType>(args)...);
215  }
216 
232  template <class... ArgumentType>
233  void Error(ArgumentType &&...args) noexcept
234  {
235  static_assert(
236  !detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
237  "Severity is already set.");
238  this->EmitLogRecord(Severity::kError, std::forward<ArgumentType>(args)...);
239  }
240 
256  template <class... ArgumentType>
257  void Fatal(ArgumentType &&...args) noexcept
258  {
259  static_assert(
260  !detail::LogRecordHasType<Severity, typename std::decay<ArgumentType>::type...>::value,
261  "Severity is already set.");
262  this->EmitLogRecord(Severity::kFatal, std::forward<ArgumentType>(args)...);
263  }
264 
265  //
266  // OpenTelemetry C++ user-facing Logs API
267  //
268 
269  inline bool Enabled(Severity severity, const EventId &event_id) const noexcept
270  {
272  {
273  return false;
274  }
275  return EnabledImplementation(severity, event_id);
276  }
277 
278  inline bool Enabled(Severity severity, int64_t event_id) const noexcept
279  {
281  {
282  return false;
283  }
284  return EnabledImplementation(severity, event_id);
285  }
286 
287  inline bool Enabled(Severity severity) const noexcept
288  {
289  return static_cast<uint8_t>(severity) >= OPENTELEMETRY_ATOMIC_READ_8(&minimum_severity_);
290  }
291 
300  virtual void Log(Severity severity,
301  const EventId &event_id,
303  const common::KeyValueIterable &attributes) noexcept
304  {
305  this->EmitLogRecord(severity, event_id, format, attributes);
306  }
307 
308  virtual void Log(Severity severity,
309  int64_t event_id,
311  const common::KeyValueIterable &attributes) noexcept
312  {
313  this->EmitLogRecord(severity, EventId{event_id}, format, attributes);
314  }
315 
316  virtual void Log(Severity severity,
318  const common::KeyValueIterable &attributes) noexcept
319  {
320  this->EmitLogRecord(severity, format, attributes);
321  }
322 
323  virtual void Log(Severity severity, nostd::string_view message) noexcept
324  {
325  this->EmitLogRecord(severity, message);
326  }
327 
328  // Convenient wrappers based on virtual methods Log().
329  // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitynumber
330 
331  inline void Trace(const EventId &event_id,
333  const common::KeyValueIterable &attributes) noexcept
334  {
335  this->Log(Severity::kTrace, event_id, format, attributes);
336  }
337 
338  inline void Trace(int64_t event_id,
340  const common::KeyValueIterable &attributes) noexcept
341  {
342  this->Log(Severity::kTrace, EventId{event_id}, format, attributes);
343  }
344 
345  inline void Trace(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
346  {
347  this->Log(Severity::kTrace, format, attributes);
348  }
349 
350  inline void Trace(nostd::string_view message) noexcept { this->Log(Severity::kTrace, message); }
351 
352  inline void Debug(const EventId &event_id,
354  const common::KeyValueIterable &attributes) noexcept
355  {
356  this->Log(Severity::kDebug, event_id, format, attributes);
357  }
358 
359  inline void Debug(int64_t event_id,
361  const common::KeyValueIterable &attributes) noexcept
362  {
363  this->Log(Severity::kDebug, EventId{event_id}, format, attributes);
364  }
365 
366  inline void Debug(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
367  {
368  this->Log(Severity::kDebug, format, attributes);
369  }
370 
371  inline void Debug(nostd::string_view message) noexcept { this->Log(Severity::kDebug, message); }
372 
373  inline void Info(const EventId &event_id,
375  const common::KeyValueIterable &attributes) noexcept
376  {
377  this->Log(Severity::kInfo, event_id, format, attributes);
378  }
379 
380  inline void Info(int64_t event_id,
382  const common::KeyValueIterable &attributes) noexcept
383  {
384  this->Log(Severity::kInfo, EventId{event_id}, format, attributes);
385  }
386 
387  inline void Info(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
388  {
389  this->Log(Severity::kInfo, format, attributes);
390  }
391 
392  inline void Info(nostd::string_view message) noexcept { this->Log(Severity::kInfo, message); }
393 
394  inline void Warn(const EventId &event_id,
396  const common::KeyValueIterable &attributes) noexcept
397  {
398  this->Log(Severity::kWarn, event_id, format, attributes);
399  }
400 
401  inline void Warn(int64_t event_id,
403  const common::KeyValueIterable &attributes) noexcept
404  {
405  this->Log(Severity::kWarn, EventId{event_id}, format, attributes);
406  }
407 
408  inline void Warn(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
409  {
410  this->Log(Severity::kWarn, format, attributes);
411  }
412 
413  inline void Warn(nostd::string_view message) noexcept { this->Log(Severity::kWarn, message); }
414 
415  inline void Error(const EventId &event_id,
417  const common::KeyValueIterable &attributes) noexcept
418  {
419  this->Log(Severity::kError, event_id, format, attributes);
420  }
421 
422  inline void Error(int64_t event_id,
424  const common::KeyValueIterable &attributes) noexcept
425  {
426  this->Log(Severity::kError, EventId{event_id}, format, attributes);
427  }
428 
429  inline void Error(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
430  {
431  this->Log(Severity::kError, format, attributes);
432  }
433 
434  inline void Error(nostd::string_view message) noexcept { this->Log(Severity::kError, message); }
435 
436  inline void Fatal(const EventId &event_id,
438  const common::KeyValueIterable &attributes) noexcept
439  {
440  this->Log(Severity::kFatal, event_id, format, attributes);
441  }
442 
443  inline void Fatal(int64_t event_id,
445  const common::KeyValueIterable &attributes) noexcept
446  {
447  this->Log(Severity::kFatal, EventId{event_id}, format, attributes);
448  }
449 
450  inline void Fatal(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
451  {
452  this->Log(Severity::kFatal, format, attributes);
453  }
454 
455  inline void Fatal(nostd::string_view message) noexcept { this->Log(Severity::kFatal, message); }
456 
457  //
458  // End of OpenTelemetry C++ user-facing Log API.
459  //
460 
461 protected:
462  // TODO: discuss with community about naming for internal methods.
463  virtual bool EnabledImplementation(Severity /*severity*/,
464  const EventId & /*event_id*/) const noexcept
465  {
466  return false;
467  }
468 
469  virtual bool EnabledImplementation(Severity /*severity*/, int64_t /*event_id*/) const noexcept
470  {
471  return false;
472  }
473 
474  void SetMinimumSeverity(uint8_t severity_or_max) noexcept
475  {
476  OPENTELEMETRY_ATOMIC_WRITE_8(&minimum_severity_, severity_or_max);
477  }
478 
479 private:
480  template <class... ValueType>
481  void IgnoreTraitResult(ValueType &&...)
482  {}
483 
484  //
485  // minimum_severity_ can be updated concurrently by multiple threads/cores, so race condition on
486  // read/write should be handled. And std::atomic can not be used here because it is not ABI
487  // compatible for OpenTelemetry C++ API.
488  //
489  mutable uint8_t minimum_severity_{kMaxSeverity};
490 };
491 } // namespace logs
logs::Logger::Debug
void Debug(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:366
nostd::unique_ptr
std::unique_ptr< _Types... > unique_ptr
Definition: includes/opentelemetry/std/unique_ptr.h:19
nostd
Definition: includes/opentelemetry/nostd/function_ref.h:14
logs::Severity::kTrace
@ kTrace
logs::Logger::~Logger
virtual ~Logger()=default
logs::Severity::kFatal
@ kFatal
logs::Severity::kError
@ kError
logs::EventId
EventId class which acts the Id of the event with an optional name.
Definition: includes/opentelemetry/logs/event_id.h:19
logs::Logger::Info
void Info(const EventId &event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:373
logs::Logger::Warn
void Warn(ArgumentType &&...args) noexcept
Writes a log with a severity of warn.
Definition: 9.2/includes/opentelemetry/logs/logger.h:209
logs::Logger::Fatal
void Fatal(nostd::string_view message) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:455
logs::Logger::Info
void Info(nostd::string_view message) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:392
nostd::unique_ptr
Provide a simplified port of std::unique_ptr that has ABI stability.
Definition: includes/opentelemetry/nostd/unique_ptr.h:45
OPENTELEMETRY_LIKELY_CONDITION
#define OPENTELEMETRY_LIKELY_CONDITION(C)
Definition: includes/opentelemetry/common/macros.h:109
logs::Logger::Debug
void Debug(const EventId &event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:352
logs::Logger::EmitLogRecord
virtual void EmitLogRecord(nostd::unique_ptr< LogRecord > &&log_record) noexcept=0
Emit a Log Record object.
logs::Logger::Fatal
void Fatal(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:450
logs::Logger::Fatal
void Fatal(int64_t event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:443
logs::Logger::Log
virtual void Log(Severity severity, nostd::string_view message) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:323
logs
Definition: includes/opentelemetry/logs/event_id.h:13
logs::Logger::EnabledImplementation
virtual bool EnabledImplementation(Severity, const EventId &) const noexcept
Definition: includes/opentelemetry/logs/logger.h:463
logs::Logger::Fatal
void Fatal(const EventId &event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:436
logs::Logger::Log
virtual void Log(Severity severity, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:316
logs::Logger::Log
virtual void Log(Severity severity, const EventId &event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Log an event.
Definition: 9.2/includes/opentelemetry/logs/logger.h:300
logs::Logger::Error
void Error(const EventId &event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:415
logs::Logger::Fatal
void Fatal(ArgumentType &&...args) noexcept
Writes a log with a severity of fatal.
Definition: 9.2/includes/opentelemetry/logs/logger.h:257
logs::kMaxSeverity
const uint8_t kMaxSeverity
Definition: includes/opentelemetry/logs/severity.h:51
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
logs::detail::LogRecordSetterTrait
Definition: includes/opentelemetry/logs/logger_type_traits.h:30
logs::Logger::Info
void Info(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:387
logs::Logger::Log
virtual void Log(Severity severity, int64_t event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:308
logs::Logger::Trace
void Trace(ArgumentType &&...args) noexcept
Writes a log with a severity of trace.
Definition: 9.2/includes/opentelemetry/logs/logger.h:137
logs::Logger::Info
void Info(ArgumentType &&...args) noexcept
Writes a log with a severity of info.
Definition: 9.2/includes/opentelemetry/logs/logger.h:185
logs::Logger::Trace
void Trace(int64_t event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:338
logs::Logger::Warn
void Warn(const EventId &event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:394
logs::Logger::Warn
void Warn(nostd::string_view message) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:413
logs::Logger::EnabledImplementation
virtual bool EnabledImplementation(Severity, int64_t) const noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:469
logs::Logger::Warn
void Warn(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:408
sdk::metrics::ValueType
nostd::variant< int64_t, double > ValueType
Definition: includes/opentelemetry/sdk/metrics/data/point_data.h:19
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
logs::Logger::Trace
void Trace(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:345
logs::LogRecord
Maintains a representation of a log in a format that can be processed by a recorder.
Definition: includes/opentelemetry/logs/log_record.h:28
logs::Logger::GetName
virtual const nostd::string_view GetName() noexcept=0
absl::move
constexpr absl::OTABSL_OPTION_NAMESPACE_NAME::remove_reference_t< T > && move(T &&t) noexcept
Definition: includes/opentelemetry/nostd/internal/absl/utility/utility.h:199
logs::Logger::Debug
void Debug(int64_t event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:359
common::KeyValueIterable
Supports internal iteration over a collection of key-value pairs.
Definition: includes/opentelemetry/common/key_value_iterable.h:17
logs::Logger::Debug
void Debug(ArgumentType &&...args) noexcept
Writes a log with a severity of debug.
Definition: 9.2/includes/opentelemetry/logs/logger.h:161
logs::Logger::Enabled
bool Enabled(Severity severity) const noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:287
logs::Severity::kWarn
@ kWarn
logs::Logger::Trace
void Trace(nostd::string_view message) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:350
logs::detail::LogRecordHasType
Definition: includes/opentelemetry/logs/logger_type_traits.h:188
logs::Logger::Warn
void Warn(int64_t event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:401
logs::Logger::Info
void Info(int64_t event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:380
logs::Logger::EmitLogRecord
void EmitLogRecord(ArgumentType &&...args)
Emit a Log Record object with arguments.
Definition: 9.2/includes/opentelemetry/logs/logger.h:114
logs::Severity
Severity
Severity Levels assigned to log events, based on Log Data Model, with the addition of kInvalid (mappe...
Definition: includes/opentelemetry/logs/severity.h:22
logs::Severity::kInfo
@ kInfo
Logger
Definition: sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/infer/engine_builder.h:50
logs::Logger::SetMinimumSeverity
void SetMinimumSeverity(uint8_t severity_or_max) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:474
logs::Logger::Error
void Error(int64_t event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:422
logs::Logger::Error
void Error(nostd::string_view message) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:434
logs::Logger::Trace
void Trace(const EventId &event_id, nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:331
logs::Severity::kDebug
@ kDebug
logs::Logger::Error
void Error(ArgumentType &&...args) noexcept
Writes a log with a severity of error.
Definition: 9.2/includes/opentelemetry/logs/logger.h:233
logs::Logger::Debug
void Debug(nostd::string_view message) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:371
logs::Logger::CreateLogRecord
virtual nostd::unique_ptr< LogRecord > CreateLogRecord() noexcept=0
Create a Log Record object.
logs::Logger::Error
void Error(nostd::string_view format, const common::KeyValueIterable &attributes) noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:429
logs::Logger::Enabled
bool Enabled(Severity severity, int64_t event_id) const noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:278
logs::Logger::Enabled
bool Enabled(Severity severity, const EventId &event_id) const noexcept
Definition: 9.2/includes/opentelemetry/logs/logger.h:269
common
Definition: includes/opentelemetry/common/attribute_value.h:14
ds3d::v2xinfer::format
static std::string format(const char *fmt,...)
Definition: sources/libs/ds3d/inference_custom_lib/ds3d_v2x_infer_custom_preprocess/tensor.hpp:31
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37