1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
5 #ifdef ENABLE_LOGS_PREVIEW
7 # include "opentelemetry/logs/logger.h"
8 # include "opentelemetry/sdk/instrumentationlibrary/instrumentation_library.h"
9 # include "opentelemetry/sdk/logs/logger_context.h"
10 # include "opentelemetry/sdk/logs/logger_provider.h"
14 OPENTELEMETRY_BEGIN_NAMESPACE
21 class Logger final
: public opentelemetry::logs::Logger
25 * Initialize a new logger.
26 * @param name The name of this logger instance
27 * @param context The logger provider that owns this logger.
30 opentelemetry::nostd::string_view name
,
31 std::shared_ptr
<LoggerContext
> context
,
32 std::unique_ptr
<instrumentationlibrary::InstrumentationLibrary
> instrumentation_library
=
33 instrumentationlibrary::InstrumentationLibrary::Create("")) noexcept
;
36 * Returns the name of this logger.
38 const opentelemetry::nostd::string_view
GetName() noexcept override
;
41 * Writes a log record into the processor.
42 * @param severity the severity level of the log event.
43 * @param message the string message of the log (perhaps support std::fmt or fmt-lib format).
45 * @param attributes the attributes, stored as a 2D list of key/value pairs, that are associated
47 * @param trace_id the trace id associated with the log event.
48 * @param span_id the span id associate with the log event.
49 * @param trace_flags the trace flags associated with the log event.
50 * @param timestamp the timestamp the log record was created.
51 * @throws No exceptions under any circumstances. */
52 void Log(opentelemetry::logs::Severity severity
,
53 nostd::string_view body
,
54 const opentelemetry::common::KeyValueIterable
&attributes
,
55 opentelemetry::trace::TraceId trace_id
,
56 opentelemetry::trace::SpanId span_id
,
57 opentelemetry::trace::TraceFlags trace_flags
,
58 opentelemetry::common::SystemTimestamp timestamp
) noexcept override
;
60 /** Returns the associated instruementation library */
61 const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary
&
62 GetInstrumentationLibrary() const noexcept
;
65 // The name of this logger
66 std::string logger_name_
;
68 // order of declaration is important here - instrumentation library should destroy after
70 std::unique_ptr
<instrumentationlibrary::InstrumentationLibrary
> instrumentation_library_
;
71 std::shared_ptr
<LoggerContext
> context_
;
76 OPENTELEMETRY_END_NAMESPACE