paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK

Home Page:https://polkadot.network/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`gum` skips logs with `CandidateHash`

AndreiEres opened this issue · comments

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Description of bug

gum seems to be skipping logs includes CandidateHash

Steps to reproduce

Minimal test case:

fn main() {
	env_logger::builder()
		.filter(None, log::LevelFilter::Info)
		.try_init()
		.unwrap();

	let a: i32 = 7;
	let hash = polkadot_primitives::Hash::repeat_byte(0xFA);
	let candidate_hash = polkadot_primitives::CandidateHash(hash);
	gum::info!(target: "bar", a, "xxx");
	gum::info!(target: "bar", a, ?hash, "xxx");
	gum::info!(target: "bar", a, ?hash, ?candidate_hash, "xxx");
}

Output:

[2024-05-31T12:03:56Z ERROR bar] xxx a=7
[2024-05-31T12:03:56Z INFO  bar] xxx a=7 hash=0xfafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafa

The third line with a candidate hash is absent.

Have you tried using sp_tracing instead of env_logger? I've seen env_logger in subsystem-benchmarks omitting several logs for some reason

This one works as expected, thank you.

fn main() {
	sp_tracing::init_for_tests();

	let a: i32 = 7;
	let hash = polkadot_primitives::Hash::repeat_byte(0xFA);
	let candidate_hash = polkadot_primitives::CandidateHash(hash);
	gum::info!(target: "bar", a, "xxx");
	gum::info!(target: "bar", a, ?hash, "xxx");
	gum::info!(target: "bar", a, ?hash, ?candidate_hash, "xxx");
}
2024-05-31T13:48:25.519985Z  INFO bar: xxx a=7
2024-05-31T13:48:25.520019Z  INFO bar: xxx a=7 hash=0xfafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafa
2024-05-31T13:48:25.520043Z  INFO bar: xxx a=7 hash=0xfafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafa candidate_hash=0xfafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafafa traceID=333610163647978885748406477874282560250

But what about env_logger. As I see we use it only in tests, maybe it's better to replace it with sp_tracing and add a note somewhere about this bug?

But what about env_logger. As I see we use it only in tests, maybe it's better to replace it with sp_tracing and add a note somewhere about this bug?

I agree it'd be good to replace env_logger with sp_tracing where possible. Not sure what's the root-cause of this bug (whether it's in gum or env_logger).