Skip to content

Commit

Permalink
tracing: Document macro arguments that MUST be static constant UTF-8 …
Browse files Browse the repository at this point in the history
…strings
  • Loading branch information
str4d committed Aug 7, 2020
1 parent c87205e commit 2ae4985
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/rust/include/tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ typedef struct TracingCallsite TracingCallsite;
/// macros such as `TracingInfo`) instead of calling this directly.
///
/// This MUST ONLY be called to assign a `static TracingCallsite*`, and all
/// string arguments MUST be static `const char*` constants.
/// string arguments MUST be static `const char*` constants, and MUST be valid
/// UTF-8.
TracingCallsite* tracing_callsite(
const char* name,
const char* target,
Expand Down Expand Up @@ -237,6 +238,9 @@ class Span
/// The `Span::Enter` method on that object records that the span has been
/// entered, and returns a RAII guard object, which will exit the span when
/// dropped.
///
/// level, target, and name MUST be static constants, and MUST be valid UTF-8
/// strings.
#define TracingSpan(level, target, name) ([&] { \
static constexpr const char* const FIELDS[] = {}; \
static TracingCallsite* CALLSITE = \
Expand All @@ -250,6 +254,8 @@ class Span
//

/// Constructs a new event.
///
/// level and target MUST be static constants, and MUST be valid UTF-8 strings.
#define TracingLog(level, target, message) \
do { \
static constexpr const char* const FIELDS[] = \
Expand All @@ -262,14 +268,34 @@ class Span
} while (0)

/// Constructs an event at the error level.
///
/// Arguments: (target, message)
///
/// target MUST be a static constant, and MUST be valid UTF-8 string.
#define TracingError(...) TracingLog("error", __VA_ARGS__)
/// Constructs an event at the warn level.
///
/// Arguments: (target, message)
///
/// target MUST be a static constant, and MUST be valid UTF-8 string.
#define TracingWarn(...) TracingLog("warn", __VA_ARGS__)
/// Constructs an event at the info level.
///
/// Arguments: (target, message)
///
/// target MUST be a static constant, and MUST be valid UTF-8 string.
#define TracingInfo(...) TracingLog("info", __VA_ARGS__)
/// Constructs an event at the debug level.
///
/// Arguments: (target, message)
///
/// target MUST be a static constant, and MUST be valid UTF-8 string.
#define TracingDebug(...) TracingLog("debug", __VA_ARGS__)
/// Constructs an event at the trace level.
///
/// Arguments: (target, message)
///
/// target MUST be a static constant, and MUST be valid UTF-8 string.
#define TracingTrace(...) TracingLog("trace", __VA_ARGS__)

#endif // TRACING_INCLUDE_H_

0 comments on commit 2ae4985

Please sign in to comment.