Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracing: don't require delimiters for format_args #288

Merged
merged 4 commits into from
Aug 19, 2019
Merged

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Aug 16, 2019

Motivation

Currently, the tracing macros require curly braces as delimiters when
a format_args macro is used in addition to structured fields, like:

info!({ field1 = value1, field2 = value2 }, "unstructured message");

This is confusing, since the delimiters are not used in other cases; it
makes the syntax more complex; and, most importantly, I think it looks
kind of ugly.

I've been planning to get rid of this when we transition to procedural
macros, but the transition is currently blocked on a compiler bug,
rust-lang/rust#62325.
(see #133 (comment))

I've been getting tired of waiting for this.

Solution:

This branch updates the tracing crate's macros to support a
format_args message after the structured key-value fields without curly
braces. For example,

let yay = "WITHOUT DELIMITERS!!!";
info!(field1 = value1, field2 = value2, "message: {}", yay);

I've updated the tests & examples in the tracing crate so that they
show this usage rather than the old usage.

The old form with curly braces is still supported, since removing it
would be a breaking change, but we'll transition it out in examples &
tutorials. (can you put a deprecated attribute on a specific macro
arm???).

Signed-off-by: Eliza Weisman [email protected]

@hawkw hawkw added kind/feature New feature or request crate/tracing Related to the `tracing` crate labels Aug 16, 2019
@hawkw hawkw self-assigned this Aug 16, 2019
Signed-off-by: Eliza Weisman <[email protected]>
@hawkw hawkw merged commit 4a8542d into master Aug 19, 2019
hawkw added a commit that referenced this pull request Aug 20, 2019
Added:

- `std::error::Error` as a new primitive type (#277)
- Support for mixing key-value fields and `format_args` messages without
  curly braces as delimiters (#288)

Changed:

- `tracing-core` dependency to 0.1.5 (#294)
- `tracing-attributes` dependency to 0.1.2

Signed-off-by: Eliza Weisman <[email protected]>
hawkw added a commit that referenced this pull request Aug 20, 2019
Added:

- `std::error::Error` as a new primitive type (#277)
- Support for mixing key-value fields and `format_args` messages without
  curly braces as delimiters (#288)

Changed:

- `tracing-core` dependency to 0.1.5 (#294)
- `tracing-attributes` dependency to 0.1.2

Signed-off-by: Eliza Weisman <[email protected]>
hawkw added a commit that referenced this pull request Aug 20, 2019
Added:

- `std::error::Error` as a new primitive type (#277)
- Support for mixing key-value fields and `format_args` messages without
  curly braces as delimiters (#288)

Changed:

- `tracing-core` dependency to 0.1.5 (#294)
- `tracing-attributes` dependency to 0.1.2

Signed-off-by: Eliza Weisman <[email protected]>
hawkw added a commit that referenced this pull request Aug 30, 2019
#288 introduced a regression that causes infinite macro recursion when
the `log` feature is enabled. This PR fixes it (by making the macros 
significantly worse).

I've also added a new test step that runs with `--all-features`, since
apparently CI doesn't already do this. Additionally, I've simplified some
of the macros a bit: it turns out we don't have to have as many match 
arms if we make the macros slightly more lenient about where commas
can show up.

Fixes #303

Signed-off-by: Eliza Weisman <[email protected]>
hawkw added a commit that referenced this pull request Aug 30, 2019
## Motivation

The old syntax for macros with messages would put the message field
first, followed by all the other fields. The new (no curly braces)
syntax (added in #288) puts messages last, inconsistently with 
everything else. Since message field ordering currently matters for 
how some subscribers (e.g. `tracing-fmt`) display events, we should 
make this somewhat more consistent.

## Solution

This branch changes the new macro syntax to put the `message` 
field first, rather than last.

Signed-off-by: Eliza Weisman <[email protected]>
@hawkw hawkw deleted the eliza/cool-macros branch September 4, 2019 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/tracing Related to the `tracing` crate kind/feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants