Reduce log verbosity
louis030195 opened this issue · comments
Hey, I'm using lopdf in https://github.com/stellar-amenities/assistants and it's polluting my logs with thousands of:
[lopdf::document] StandardEncoding
Any recommendation to reduce verbosity?
I saw
pub fn decode_text(encoding: Option<&str>, bytes: &[u8]) -> String {
if let Some(encoding) = encoding {
info!("{}", encoding);
match encoding {
"StandardEncoding" => bytes_to_string(encodings::STANDARD_ENCODING, bytes),
"MacRomanEncoding" => bytes_to_string(encodings::MAC_ROMAN_ENCODING, bytes),
"MacExpertEncoding" => bytes_to_string(encodings::MAC_EXPERT_ENCODING, bytes),
"WinAnsiEncoding" => bytes_to_string(encodings::WIN_ANSI_ENCODING, bytes),
"UniGB-UCS2-H" | "UniGB−UTF16−H" => UTF_16BE.decode(bytes).0.to_string(),
"Identity-H" => "?Identity-H Unimplemented?".to_string(), // Unimplemented
_ => String::from_utf8_lossy(bytes).to_string(),
}
} else {
bytes_to_string(encodings::STANDARD_ENCODING, bytes)
}
}
Not sure what's the best practice here with the info
I had the same issue with other libraries and my workaround is to configure the log library to filter some kind of messages.
I use fern https://docs.rs/fern/latest/fern/struct.Dispatch.html#method.level_for and with this you can set a custom level for lopdf::document
I have the same problem so I always put lopdf=off
in my env filter.
I'm not very experienced with logging, but if I understand the docs of log
correctly, it is not the libraries (lopdf's) job to filter the logs.
This job falls to the logging implementation, which in your case is probably env_logger
.
Setting RUST_LOG=info,lopdf=warn
or even RUST_LOG=info,lopdf=off
should filter/disable any logging from lopdf.
Maybe we could also lower the log level in this particular instance from info
to debug
, IMO it isn't that interesting to know which encoding was used, especially without even knowing in which object.