Skip to content

Better support for verbosity levels #129

Description

@AhmedMozaly

Thank you for maintaining such a great crate!

I recently made the switch from anyhow to rootcause as well! The experience has been really great so far, but I did run into one specific challenge: the default log format is a bit too heavy to send directly in an API response (for those cases where I need to do that).

I wish this use case were a bit more "out-of-the-box" in rootcause, as I imagine I'm not the only one needing to serve errors over an API. To get around it, I implemented a custom ReportFormatter to separate internal log verbosity from user-facing responses.

I started by installing the hook:

    Hooks::new()
        .report_formatter(CompactErrorFormatter)
        .install()
        .context("Failed to install rootcause hooks")?;

The implementation essentially checks the report_formatting_function: when it's Display, it uses a compact format for the API, while leaving the Debug output as-is for internal logging:

It works well, but it would be awesome if the library had a built-in way to toggle between "internal" and "external" formatting more easily.

for context, this issue is created out of reddit comment
https://www.reddit.com/r/rust/comments/1qyrt8f/comment/o45z5qh/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions