Skip to content

Commit

Permalink
improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Feb 14, 2025
1 parent 808d3b7 commit 38c38e7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
61 changes: 61 additions & 0 deletions docs/cheat_sheet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,64 @@ Outputs:
Order is timestamp=17220432928367021 symbol=AAPL price=220.1 quantity=100

Order [order: timestamp=17220432928367021 symbol=AAPL price=220.1 quantity=100]

Using External fmt Formatter Specializations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Quill uses a custom namespace, ``fmtquill``, and requires formatter specializations to be defined under the same namespace. However, when an external ``libfmt`` is also used, you can reuse existing ``fmt::formatter`` specializations instead of redefining them.

.. note::

Ensure that the major version of your external ``libfmt`` matches Quill's internal version to avoid ABI incompatibilities.

If you choose to reuse an existing ``fmt::formatter`` specialization, you can derive from it. However, you must template both ``parse`` and ``format`` to support different ``Context`` types.

.. code:: cpp
struct User
{
int id = 1;
int age = 32;
};
template <>
struct fmt::formatter<User>
{
template <typename TFormatParseCtx>
constexpr auto parse(TFormatParseCtx& ctx) { return ctx.begin(); }
template <typename TFormatCtx>
auto format(::User const& user, TFormatCtx& ctx) const
{
return fmt::format_to(ctx.out(), "id: {}, age: {}", user.id, user.age);
}
};
template <>
struct fmtquill::formatter<User> : fmt::formatter<User>
{
};
template <>
struct quill::Codec<User> : TriviallyCopyableTypeCodec<User>
{
};
If the external specialization derives from ``fmt::ostream_formatter``, the above approach won't work because ``parse`` is not templated. In this case, you must directly specialize ``fmtquill::ostream_formatter``.

.. code:: cpp
template <>
struct fmt::formatter<User> : fmt::ostream_formatter
{
};
template <>
struct fmtquill::formatter<User> : fmtquill::ostream_formatter
{
};
template <>
struct quill::Codec<User> : DeferredFormatCodec<User>
{
};
2 changes: 2 additions & 0 deletions docs/logging_macros.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. title:: Logging Macros

Logging Macros
==============

Expand Down

0 comments on commit 38c38e7

Please sign in to comment.