J-F-Liu / lopdf

A Rust library for PDF document manipulation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.