-
Notifications
You must be signed in to change notification settings - Fork 13.3k
liblog: add the loglevel, file and linenumber to the log output #13708
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
Conversation
@pcwalton has had concerns in the past about the code bloat of passing around a filename and line number. I do agree that this is quite useful, but I would expect loggers to only take a level and a format string rather than litany of other relevant arguments. Instead, perhaps the macro could change similar to this? macro_rules! log_with_location(
($lvl:expr, $fmt $($arg:tt)*) => ({
log!($lvl, concat!("{} {}:{}", $fmt), ::log::level_to_str($lvl), file!(), line!() $($arg)*)
})
) |
I'd actually think a Logger would rather receive a |
I agree that code bloat could potentially be a problem, not sure to what extent 2 static arguments make much of a difference. I don't agree with the proposed solution though. What's the point of making custom loggers possible, if the majority of the formatting is already prescribed? If the two additional arguments are the main concern, then gathering them into a struct as proposed by @seanmonstar would be a nicer solution IMO. |
In that case, I like the suggestion by @seanmonstar as well, it'd also allow some nice extensibility in the future? Would you be ok with making that change @Blei? Also, you may want to print just the filename of the paths because sometimes the path to the file can be quite long. |
(sorry it took me a bit to get back to this!) |
@alexcrichton I can make a PR with what I had in mind. One question: how would I use the fn log(record: &LogRecord) {
write!(stdout, "{} {}: {}", record.file, record.line, record.args);
} |
Something along the lines of: fn log(record: &LogRecord) -> IoResult<()> {
try!(write!(stdout, "{} {}: ", record.file, record.line));
fmt::write(stdout, record.args)
} |
Ouch. Would it make sense to add a |
Sure! |
Closing in favor of #13912 |
@seanmonstar Was it intentional using |
Nope, that was a mistake. Woops! |
Suggested by, and closes rust-lang#13704. changelog: [`unnecessary_map_or`]: use a clearer lint message
No description provided.