tracing: When creating my own FormatEvent type, I have to duplicate a lot of code

Feature Request

Crates

tracing-subscriber

Motivation

I’m trying to customize the log lines in the terminal. For that I need to write my own FormatEvent.

I copy-pasted the code of the one provided by tracing-subsriber called Format. But I had to duplicate a lot of other objects before being able to make it useful: FmtLevel, FmtThreadName, FmtCtx, even format::time::write()

Example here

Proposal

Not sure. Maybe make some common things pub?

Alternatives

Not sure either.

cc @davidbarsky

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 2
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Being unable to write custom formatters without copying a ton of code, forking the crate, or suffering the performance impact from serializing and reserializing JSON every time we write has, singlehandedly, made this one of the most frustrating logging libraries I’ve ever had the displeasure of using. Please fix this.

I understand the frustration, but I’d encourage a more constructive tone. The maintainers are offering this crate for free, and respectful feedback helps everyone. It’s not about the technical point — which is valid — but how it’s delivered. There’s always a way to express concerns without discouraging those doing the work.

Being unable to write custom formatters without copying a ton of code, forking the crate, or suffering the performance impact from serializing and reserializing JSON every time we write has, singlehandedly, made this one of the most frustrating logging libraries I’ve ever had the displeasure of using. Please fix this.

Last lastly: to be honest --but not entirely related to this issue-- we also encountered an issue with the key-value thingy in the span macros. They allow a few types (u64, i64, String and bool) but in my use case I need to send a HashMap of some sort. In slog they had a more flexible key-value thingy that uses serde’s Serialize so we could send properly (we were using slog before).

@cecton Would #886 help here?

I think the issue that would help here is #819. We’re definitely interested in adding serde support in the new value system for tracing 0.2.

I’m a little wary of making too much of the current interface pub — then, it becomes a breaking change to remove it in the future. Rather than making FmtContext public and committing to maintaining it forever, I’d prefer to refactor the API so that the FmtContext type isn’t necessary (https://github.com/tokio-rs/tracing/issues/658).