Tracing crate - rolling file subscriber

Anyone have an example of using tracing with a subscriber that writes to file - with auto-rolling, ala log4j's rolling file appender?

Even setting up a file-based subscriber is surprisingly low-level and complex. I've not seen a rolling-file example anywhere.

That may be because it's somehow expected that your service will run as a systemd unit and its logging output will be managed by journald, or run alone in a virtual machine where it'll send its log to another server like grafana, opentelemetry, or others.

Not saying it's a good status quo. But that may be the unspoken unwritten assumption.

2 Likes

You may find that tracing-appender meets your needs. There is also log4rs, but that operates on log events, not tracing spans, but I think there are ways you can forward them.

I agree that configuring the logging/tracing subscribers properly feels more complicated then it should be. Here's a rolling file example with tracing-appender and log4rs. tracing-appender doesn't have compression of the rolling files. Also note there are some known formatting bugs

3 Likes

We don't really have a need for grafana or opentelemetry. And we've never run our Linux processes as services. Maybe something to look in to, though.

Yes, this tracing-appender sample is perfect.

There's also rolling-file.

You could log to stdout and pipe it to rotatelogs

That way, not every program has to reimplement log rotation. It feels more unixy to me.

2 Likes