Skip to content

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

Closed
@FabienTregan

Description

@FabienTregan

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions