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

fix: level! macros with constant field names in the first position #2883

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions tracing/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,6 @@ macro_rules! trace {
$crate::event!(
target: module_path!(),
$crate::Level::TRACE,
{},
$($arg)+
)
);
Expand Down Expand Up @@ -1822,7 +1821,6 @@ macro_rules! debug {
$crate::event!(
target: module_path!(),
$crate::Level::DEBUG,
{},
$($arg)+
)
);
Expand Down Expand Up @@ -2110,7 +2108,6 @@ macro_rules! info {
$crate::event!(
target: module_path!(),
$crate::Level::INFO,
{},
$($arg)+
)
);
Expand Down Expand Up @@ -2391,7 +2388,6 @@ macro_rules! warn {
$crate::event!(
target: module_path!(),
$crate::Level::WARN,
{},
$($arg)+
)
);
Expand Down Expand Up @@ -2668,7 +2664,6 @@ macro_rules! error {
$crate::event!(
target: module_path!(),
$crate::Level::ERROR,
{},
$($arg)+
)
);
Expand Down
54 changes: 54 additions & 0 deletions tracing/tests/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ fn constant_field_name() {
)
};
let (collector, handle) = collector::mock()
.event(expect_event())
.event(expect_event())
.event(expect_event())
.event(expect_event())
.event(expect_event())
.event(expect_event())
.event(expect_event())
.event(expect_event())
.only()
Expand All @@ -439,6 +445,54 @@ fn constant_field_name() {
},
"quux"
);
tracing::info!(
{ std::convert::identity(FOO) } = "bar",
{ "constant string" } = "also works",
foo.bar = "baz",
"quux"
);
tracing::info!(
{
{ std::convert::identity(FOO) } = "bar",
{ "constant string" } = "also works",
foo.bar = "baz",
},
"quux"
);
tracing::event!(
Level::INFO,
{ std::convert::identity(FOO) } = "bar",
{ "constant string" } = "also works",
foo.bar = "baz",
"{}",
"quux"
);
tracing::event!(
Level::INFO,
{
{ std::convert::identity(FOO) } = "bar",
{ "constant string" } = "also works",
foo.bar = "baz",
},
"{}",
"quux"
);
tracing::info!(
{ std::convert::identity(FOO) } = "bar",
{ "constant string" } = "also works",
foo.bar = "baz",
"{}",
"quux"
);
tracing::info!(
{
{ std::convert::identity(FOO) } = "bar",
{ "constant string" } = "also works",
foo.bar = "baz",
},
"{}",
"quux"
);
});

handle.assert_finished();
Expand Down
32 changes: 31 additions & 1 deletion tracing/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,15 @@ fn trace() {
trace!(foo = ?3, bar.baz = %2, quux = false);
trace!(foo = 3, bar.baz = 2, quux = false);
trace!(foo = 3, bar.baz = 3,);
trace!("foo" = 3, bar.baz = 3,);
trace!(foo = 3, "bar.baz" = 3,);
trace!("foo");
trace!("foo: {}", 3);
trace!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42);
trace!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42);
trace!(foo = 3, bar.baz = 3, "hello world {:?}", 42,);
trace!({ foo = 3, bar.baz = 80 }, "quux");
trace!({ "foo" = 3, "bar.baz" = 80 }, "quux");
trace!({ foo = 2, bar.baz = 79 }, "quux {:?}", true);
trace!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false);
trace!({ foo = 2, bar.baz = 78 }, "quux");
Expand All @@ -579,6 +582,9 @@ fn trace() {
trace!(?foo);
trace!(%foo);
trace!(foo);
trace!("foo" = ?foo);
trace!("foo" = %foo);
trace!("foo" = foo);
trace!(name: "foo", ?foo);
trace!(name: "foo", %foo);
trace!(name: "foo", foo);
Expand Down Expand Up @@ -615,12 +621,15 @@ fn debug() {
debug!(foo = ?3, bar.baz = %2, quux = false);
debug!(foo = 3, bar.baz = 2, quux = false);
debug!(foo = 3, bar.baz = 3,);
debug!("foo" = 3, bar.baz = 3,);
debug!(foo = 3, "bar.baz" = 3,);
debug!("foo");
debug!("foo: {}", 3);
debug!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42);
debug!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42);
debug!(foo = 3, bar.baz = 3, "hello world {:?}", 42,);
debug!({ foo = 3, bar.baz = 80 }, "quux");
debug!({ "foo" = 3, "bar.baz" = 80 }, "quux");
debug!({ foo = 2, bar.baz = 79 }, "quux {:?}", true);
debug!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false);
debug!({ foo = 2, bar.baz = 78 }, "quux");
Expand All @@ -639,6 +648,9 @@ fn debug() {
debug!(?foo);
debug!(%foo);
debug!(foo);
debug!("foo" = ?foo);
debug!("foo" = %foo);
debug!("foo" = foo);
debug!(name: "foo", ?foo);
debug!(name: "foo", %foo);
debug!(name: "foo", foo);
Expand Down Expand Up @@ -675,12 +687,15 @@ fn info() {
info!(foo = ?3, bar.baz = %2, quux = false);
info!(foo = 3, bar.baz = 2, quux = false);
info!(foo = 3, bar.baz = 3,);
info!("foo" = 3, bar.baz = 3,);
info!(foo = 3, "bar.baz" = 3,);
info!("foo");
info!("foo: {}", 3);
info!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42);
info!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42);
info!(foo = 3, bar.baz = 3, "hello world {:?}", 42,);
info!({ foo = 3, bar.baz = 80 }, "quux");
info!({ "foo" = 3, "bar.baz" = 80 }, "quux");
info!({ foo = 2, bar.baz = 79 }, "quux {:?}", true);
info!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false);
info!({ foo = 2, bar.baz = 78 }, "quux");
Expand All @@ -699,6 +714,9 @@ fn info() {
info!(?foo);
info!(%foo);
info!(foo);
info!("foo" = ?foo);
info!("foo" = %foo);
info!("foo" = foo);
info!(name: "foo", ?foo);
info!(name: "foo", %foo);
info!(name: "foo", foo);
Expand Down Expand Up @@ -735,12 +753,15 @@ fn warn() {
warn!(foo = ?3, bar.baz = %2, quux = false);
warn!(foo = 3, bar.baz = 2, quux = false);
warn!(foo = 3, bar.baz = 3,);
warn!("foo" = 3, bar.baz = 3,);
warn!(foo = 3, "bar.baz" = 3,);
warn!("foo");
warn!("foo: {}", 3);
warn!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42);
warn!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42);
warn!(foo = 3, bar.baz = 3, "hello world {:?}", 42,);
warn!({ foo = 3, bar.baz = 80 }, "quux");
warn!({ "foo" = 3, "bar.baz" = 80 }, "quux");
warn!({ foo = 2, bar.baz = 79 }, "quux {:?}", true);
warn!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false);
warn!({ foo = 2, bar.baz = 78 }, "quux");
Expand All @@ -759,6 +780,9 @@ fn warn() {
warn!(?foo);
warn!(%foo);
warn!(foo);
warn!("foo" = ?foo);
warn!("foo" = %foo);
warn!("foo" = foo);
warn!(name: "foo", ?foo);
warn!(name: "foo", %foo);
warn!(name: "foo", foo);
Expand Down Expand Up @@ -795,15 +819,18 @@ fn error() {
error!(foo = ?3, bar.baz = %2, quux = false);
error!(foo = 3, bar.baz = 2, quux = false);
error!(foo = 3, bar.baz = 3,);
error!("foo" = 3, bar.baz = 3,);
error!(foo = 3, "bar.baz" = 3,);
error!("foo");
error!("foo: {}", 3);
error!(foo = ?3, bar.baz = %2, quux = false, "hello world {:?}", 42);
error!(foo = 3, bar.baz = 2, quux = false, "hello world {:?}", 42);
error!(foo = 3, bar.baz = 3, "hello world {:?}", 42,);
error!({ foo = 3, bar.baz = 80 }, "quux");
error!({ "foo" = 3, "bar.baz" = 80 }, "quux");
error!({ foo = 2, bar.baz = 79 }, "quux {:?}", true);
error!({ foo = 2, bar.baz = 79 }, "quux {:?}, {quux}", true, quux = false);
error!({ foo = 2, bar.baz = 78, }, "quux");
error!({ foo = 2, bar.baz = 78 }, "quux");
error!({ foo = ?2, bar.baz = %78 }, "quux");
error!(name: "foo", foo = 3, bar.baz = 2, quux = false);
error!(name: "foo", target: "foo_events", foo = 3, bar.baz = 2, quux = false);
Expand All @@ -819,6 +846,9 @@ fn error() {
error!(?foo);
error!(%foo);
error!(foo);
error!("foo" = ?foo);
error!("foo" = %foo);
error!("foo" = foo);
error!(name: "foo", ?foo);
error!(name: "foo", %foo);
error!(name: "foo", foo);
Expand Down
Loading