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

Inconsistency in formated output with respect to functions in standard lib. #407

Closed
FabienTregan opened this issue Aug 6, 2020 · 4 comments

Comments

@FabienTregan
Copy link

FabienTregan commented Aug 6, 2020

Using log 0.4.11, the following code:

#[macro_use]
extern crate log;
extern crate stderrlog;

fn main() {
	stderrlog::new().module(module_path!()).init().unwrap();

	println!("{{{{this}}}} prints a way");
	println!("{{{{this}}}} prints {}", "in the same way");

	error!("{{{{this}}}} logs a way");
	error!("{{{{this}}}} logs {}", "in another way");
}

produces this output:

{{this}} prints a way
{{this}} prints in the same way
ERROR - {{{{this}}}} logs a way
ERROR - {{this}} logs in another way

This is due to

let _ = __log_format_args!($message);
checking that the message is correct when there are no arguments but ignoring the result and logging the original message.
Standard rust macros (format!, write!, println!, ...) call std::format_args! which already handles both cases:
https://github.com/rust-lang/rust/blob/ac48e62db85e6db4bbe026490381ab205f4a614d/library/alloc/src/macros.rs#L105-L110
https://github.com/rust-lang/rust/blob/4b0882cfaa33de2796eac01afeac69097fbccbd2/library/core/src/macros/mod.rs#L792-L795

If you think it is desirable to have a behavior that is analog to rust macros, I can try doing the change.

@FabienTregan
Copy link
Author

The same code with 4.0.8 gives the expected result.

@sfackler
Copy link
Member

sfackler commented Aug 7, 2020

We started special-casing the no-args case to minimize codegen, but it seems like that's not quite the correct behavior: https://github.com/rust-lang/log/blob/master/src/lib.rs#L1388-L1403.

That special case will need to go away anyway to support https://github.com/rust-lang/rfcs/blob/master/text/2795-format-args-implicit-identifiers.md.

@sfackler
Copy link
Member

There's a new API on Arguments that we should be able to use to recover this optimization: rust-lang/rust#74056

@sfackler
Copy link
Member

Fixed by #446. If Arguments.as_str stabilizes, we can use that to add the optimization back.

EFanZh pushed a commit to EFanZh/log that referenced this issue Jul 23, 2023
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.14.0 to 1.15.0.
- [Release notes](https://github.com/matklad/once_cell/releases)
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](matklad/once_cell@v1.14.0...v1.15.0)

---
updated-dependencies:
- dependency-name: once_cell
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants