neqo icon indicating copy to clipboard operation
neqo copied to clipboard

Replace `neqo_common::log` with `log` crate

Open mxinden opened this issue 1 year ago • 2 comments

neqo* currently uses neqo_common::log for all things logging. It is a wrapper around the log crate.

What is the benefit of using neqo_common::log over using the log crate directly? From what I can tell:

  • neqo_common::log does not require explicit instantiation of the logger (e.g. via env_logger::init) but instead tries to initialize on each log invocation. https://github.com/mozilla/neqo/blob/c209c439e2aea408594273f6f1c423bbfe723f4f/neqo-common/src/log.rs#L84-L90
  • Uses elapsed time instead of absolute time https://github.com/mozilla/neqo/blob/c209c439e2aea408594273f6f1c423bbfe723f4f/neqo-common/src/log.rs#L69-L71

Are the benefits worth a custom way of logging? Should a library instantiate a logger instead of the conventional instantiation by the calling binary?

Related, other Mozilla code using log: https://searchfox.org/mozilla-central/search?q=%5Elog+%3D&path=*Cargo.toml&case=true&regexp=true

mxinden avatar Jul 04 '24 10:07 mxinden

I'd be OK with removing this.

larseggert avatar Jul 04 '24 12:07 larseggert

There are some special things neqo_common::log allows, e.g., https://github.com/mozilla/neqo/blob/9f0a86db7f125d731cd10816e57728597d8437b5/neqo-crypto/src/agent.rs#L898-L902

Can we do this with log?

larseggert avatar Jul 11 '24 09:07 larseggert

So I worked on this a bit in #2291. I do think we need a wrapper of some sort like we have in neqo-common::log, because otherwise we'd need to initialize env_logger in every single test, which is a pain.

larseggert avatar Dec 18 '24 11:12 larseggert

Agreed. I didn't think of env_logger instantiation in unit tests. Sorry about that.

mxinden avatar Dec 18 '24 11:12 mxinden

OK. I will leave neqo-common::log in place w/some changes.

larseggert avatar Dec 18 '24 13:12 larseggert