Logging with indentation

I’d like to add some debug logging to librsvg. It has a highly recursive code flow because SVG elements draw themselves, plus their children, and so on recursively.

Ideally I’d like the output to look something like this:

group id="foo" {
    affine: { ... }
    computed_values: { a big struct goes here }
    children {
        rect id="bar" {
            affine: { ... }
            computed_values: { another big struct }
        path id="baz" { ... }

Is there a logging crate that will do this kind of nesting? I could write some sort of wrapper around the “log” crate to do this myself, but would rather not :slight_smile:

The output is not intended to go to system logs or anything like that. It’s just debug output.

I don’t know of anything like this, but it would be really cool to have an implementation of something like Eliot (a Python library for hierarchical logging) in Rust.

ISTM that the most significant use cases for indented logging are at the application level, where, luckily, you already are in control of which logger implementation is in use. I’d think you could probably just use a logger implementation that provides a facility for adjusting indentation, and use that facility explicitly in your code.

(a great starting place for a custom logger implementation is fern, which is easy to hook into.)

(Or actually, now that I’ve looked at it more closely, log itself is already easy to hook into. fern simply adds some bells and whistles)

It looks more like a usecase for your own formatting, but try slog.

This topic was automatically closed after 13 days. We invite you to open a new topic if you have further questions or comments.