Skip to content

Commit

Permalink
Adding new Logger:log() method (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Sep 30, 2021
1 parent 21a441e commit 4c61f7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
21 changes: 19 additions & 2 deletions api/include/opentelemetry/logs/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Logger
*/
template <class T,
nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
inline void Log(Severity severity, const T &attributes) noexcept
void Log(Severity severity, const T &attributes) noexcept
{
this->Log(severity, "", "", std::map<std::string, std::string>{}, attributes, {}, {}, {},
std::chrono::system_clock::now());
Expand All @@ -157,7 +157,7 @@ class Logger
*/
template <class T,
nostd::enable_if_t<common::detail::is_key_value_iterable<T>::value> * = nullptr>
inline void Log(Severity severity, nostd::string_view name, const T &attributes) noexcept
void Log(Severity severity, nostd::string_view name, const T &attributes) noexcept
{
this->Log(severity, name, "", std::map<std::string, std::string>{}, attributes, {}, {}, {},
std::chrono::system_clock::now());
Expand Down Expand Up @@ -189,6 +189,23 @@ class Logger
this->Log(severity, name, "", {}, attributes, {}, {}, {}, std::chrono::system_clock::now());
}

/**
* Writes a log.
* @param severity The severity of the log
* @param name The name of the log
* @param attributes The attributes, stored as a 2D list of key/value pairs, that are associated
* with the log event
*/
void Log(Severity severity,
nostd::string_view name,
common::KeyValueIterable &attributes) noexcept
{
this->Log(severity, name, {},
common::KeyValueIterableView<
std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>>({}),
attributes, {}, {}, {}, std::chrono::system_clock::now());
}

/** Trace severity overloads **/

/**
Expand Down
4 changes: 2 additions & 2 deletions sdk/include/opentelemetry/sdk/logs/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class Logger final : public opentelemetry::logs::Logger
nostd::string_view body,
const opentelemetry::common::KeyValueIterable &resource,
const opentelemetry::common::KeyValueIterable &attributes,
trace::TraceId trace_id,
trace::SpanId span_id,
opentelemetry::trace::TraceId trace_id,
opentelemetry::trace::SpanId span_id,
trace::TraceFlags trace_flags,
opentelemetry::common::SystemTimestamp timestamp) noexcept override;

Expand Down

0 comments on commit 4c61f7b

Please sign in to comment.