Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flow.log: Add printf-format capability. #78

Open
ygoldfeld opened this issue Mar 10, 2024 · 0 comments
Open

flow.log: Add printf-format capability. #78

ygoldfeld opened this issue Mar 10, 2024 · 0 comments
Labels
enhancement New feature or request from-akamai-pre-open Issue origin is Akamai, before opening source

Comments

@ygoldfeld
Copy link
Contributor

Filed by @ygoldfeld pre-open-source:

FLOW_LOG_ macros operate with << ostream semantics.

In general we should add printf-format semantics as well. Macros cannot be overloaded, so need to come up with a decent name; maybe FLOW_LOGF_* (analogous to printf, as in print-formatted, log-formatted). Though it breaks the coding style convention of putting the namespace into the macro. Maybe FLOW_LOG_F_* or FLOW_LOG_FMT_*.

In terms of implementation:

---begin mostly ignoring---
There is Boost.format; and [https://abseil.io/tips/124] (which means abseil would become a dependency of Flow). Boost.format might be unsuitable due to requiring % instead of comma. Abseil str_format looks pretty badass. One thing I don't see in it, or anywhere else, is direct support for output of type T, where ostream<<T is supplied; this way a given object outputs its string representation directly into the logged stream. Functionally it's fine, in that one can always do StrFormat("%s", flow::util::ostream_op_string(item_of_type_t)); it is just a bit slower than one would want. There is support for StrFormat("%v", item_of_type_t), but one must supply an overload for a certain thingie for const T&, but either one then has to write a re-impl of ostream<<T, or simply use the latter (but then seems it's still slow involving a temp std::string). But details. Come up with something decent to use and perf-wise; and get on with it.
---stop mostly ignoring---

Update in 1/2024: C++ 20 adopted the fmt library which is mega-fast and good. Before C++20 it is available separately, both headers-only and not. I'd say that automatically makes it the top contender over the above. It has other uses as well such as to print nice time stamps quickly in flow.log. No-brainer.
Update in 2/2024: Flow now depends on fmt (for a certain recent perf improvement)! So for sure we should use it for this.

mentioned std::to_string() overloads; investigate those for relevance; might not be relevant.

@ygoldfeld ygoldfeld added enhancement New feature or request from-akamai-pre-open Issue origin is Akamai, before opening source labels Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request from-akamai-pre-open Issue origin is Akamai, before opening source
Projects
None yet
Development

No branches or pull requests

1 participant