odygrd / quill

Asynchronous Low Latency C++ Logging Library
MIT License
1.55k stars 158 forks source link

I've defined fmt::formatter for my struct type. Can I use it in quill? #614

Open JaydenFish opened 20 hours ago

JaydenFish commented 20 hours ago

Or I should defined it again with quill::Codec?

odygrd commented 12 hours ago

Hey! Unfortunately, you'll need to define the formatter again under fmtquill. Quill uses its own bundled version of libfmt, so it's currently not possible to reuse an existing fmt::formatter directly without redefining it.

JaydenFish commented 10 hours ago

it's really troublesome

odygrd commented 7 hours ago

I understand it can be inconvenient. However, different projects often use different major versions of libfmt, which can lead to compatibility issues if Quill’s bundled version and your version have different APIs.

Quill did previously support using an external fmtlib, but maintaining compatibility with multiple major versions—each with potentially different APIs—proved challenging.

In the latest versions, Quill uses only its bundled libfmt, so it’s best to think of it as Quill's internal formatting library rather than a standalone libfmt. Imagine if Quill used its own custom formatting library entirely—it would similarly require its own formatter definitions.

The fmtquill formatter is mainly needed if you want to shift formatting to the backend thread on the hot path. For the cold path or debug statements, you can pass a preformatted string directly to the logging macro.

As an alternative, you could create a macro that defines the same formatter twice under different namespaces. Let me know if you’d like an example of how that could work