Skip to content

Support binding positional arguments to named arguments #648

@espakm

Description

@espakm

I get a compiler error when trying to use named arguments in the format string of a log message.

To reproduce:

quill::Logger* logger = quill::Frontend::create_or_get_logger(
    "root", quill::Frontend::create_or_get_sink<quill::ConsoleSink>("sink_id_1"));
std::string whoever = "you";
LOG_INFO(logger, "Hello, {}!", whoever);                              // GOOD
fmt::println("Hello, {whoever}!", fmt::arg("whoever", whoever));      // GOOD
LOG_INFO(logger, "Hello, {whoever}!", fmt::arg("whoever", whoever));  // BAD

The error:

In file included from /Users/miklos.espak/.conan/data/quill/8.0.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/quill/Frontend.h:9:
In file included from /Users/miklos.espak/.conan/data/quill/8.0.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/quill/Logger.h:11:
/Users/miklos.espak/.conan/data/quill/8.0.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/quill/core/Codec.h:62:3: error: static assertion failed due to requirement 'always_false_v<fmt::detail::named_arg<char, std::string>>': 
+------------------------------------------------------------------------------+
|                       Missing Codec for Type 'Arg'                           |
+------------------------------------------------------------------------------+

Error: A codec for the specified type 'Arg' is not available.

Possible solutions:
1. If Arg is an STL type:
   - Ensure you have included the necessary headers for the specific STL type you are using from the quill/std folder.

2. If Arg is a user-defined type:
   - Define a custom Codec for your type.
   - Consider passing the value as a string instead.

Note: The specific type of 'Arg' can be found in the compiler error message.
      Look for the instantiation of 'codec_not_found_for_type<Arg>' in the error output.
      The compiler should indicate what type 'Arg' represents in this instance.

For more information see https://quillcpp.readthedocs.io/en/latest/cheat_sheet.html

  static_assert(
  ^
/Users/miklos.espak/.conan/data/quill/8.0.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/quill/core/Codec.h:141:15: note: in instantiation of function template specialization 'quill::detail::codec_not_found_for_type<fmt::detail::named_arg<char, std::string>>' requested here
      detail::codec_not_found_for_type<Arg>();
              ^
/Users/miklos.espak/.conan/data/quill/8.0.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/quill/core/Codec.h:300:47: note: in instantiation of member function 'quill::Codec<fmt::detail::named_arg<char, std::string>>::compute_encoded_size' requested here
  ((total_sum += Codec<remove_cvref_t<Args>>::compute_encoded_size(conditional_arg_size_cache, args)), ...);
                                              ^
/Users/miklos.espak/.conan/data/quill/8.0.0/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/quill/Logger.h:128:15: note: in instantiation of function template specialization 'quill::detail::compute_encoded_size_and_cache_string_lengths<fmt::detail::named_arg<char, std::string>>' requested here
      detail::compute_encoded_size_and_cache_string_lengths(
              ^

I want to use named args in a code generator that generates log functions. (It used to generate ones that use Boost::logging, but would like to switch them over to Quill.)

It would be nice to have this working out of the box, but some hints how to get around it by writing a custom codec (for fmt::detail::named_arg, I guess), would also be much approciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions