Macro info

Source
info!() { /* proc-macro */ }
Expand description

Emit an event at the info level.

Event emission is non-blocking.

See the guide for more details on logging.

§Examples

Note that debug, info, warn, and error use the same syntax.

Emitting an event with captured properties in the template:

let x = 42;
let y = true;

emit::emit!("got {x} and {y}");

Emitting an event with captured properties after the template:

let x = 42;
let y = true;

emit::emit!("something of note", x, y);

Specifying control parameters before the template (in this example, mdl):

emit::emit!(mdl: emit::path!("a::b"), "something of note");

§Syntax

(control_param),* template_literal, (property),*

where

  • control_param: A Rust field-value with a pre-determined identifier (see below).
  • template_literal: A template string literal (see below).
  • property: A Rust field-value for a property to capture.

§Control parameters

This macro accepts the following optional control parameters:

nametypedescription
rtimpl emit::runtime::RuntimeThe runtime to emit the event through.
mdlimpl Into<emit::Path>The module the event belongs to. If unspecified the current module path is used.
extentimpl emit::ToExtentThe extent to use on the event. If it resolves to None then the clock on the runtime will be used to assign a point extent.
propsimpl emit::PropsA base set of properties to add to the event.
evtimpl emit::event::ToEventA base event to emit. Any properties captured by the macro will be appended to the base event. If this control parameter is specified then mdl, props, and extent cannot also be set.
whenimpl emit::FilterA filter to use instead of the one configured on the runtime.

§Template literals

Templates are text literals that include regular text with holes. A hole is a point in the template where a property should be interpolated in.

  • template_literal: " (text | hole)* "
  • text: A fragment of plain text where { are escaped as {{ and } are escaped as }}.
  • hole: { property }
  • property: A Rust field-value expression.

The following are all examples of templates:

"some text"
 ├───────┘
 text
"some text and {x}"
 ├────────────┘ │
 text           property
"some {{text}} and {x: 42} and {y}"
 ├────────────────┘ ├───┘ └───┤ │
 text               property  │ property
                              text

See the guide for more details and examples of templates.

§Properties

Properties that appear within the template or after it are added to the emitted event. The identifier of the property is its key. Property capturing can be adjusted through the as_* attribute macros.

See the guide for more details on property capturing.