[core] Setting up fmt with custom config structure for logging system#2964
Merged
ethouris merged 61 commits intoAug 26, 2025
Conversation
…pdated sfmt implementation
…adowed local variables
added 7 commits
August 8, 2025 16:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This provides the helper class
fmt_sender_proxywith a helper functionfmtso that nondefault formatting can be used in place. All intermediate formatting is done usingstd::ostringstreamorstd::stringstreamclass.This proposes a new API for all iostream-based solutions, just like also iostream itself. For example: In order to write values of
a,x,bin the form like:17-0001dead-42usingprintfyou need:And in the standard iostream, you'd have to do the following:
(Setting width back to 0 is not necessary because it's done after every printed integer.)
With this ofmt facility the same can be written simply as:
To use operator << this way, you have to also include
ofmt_iostream.h. For the LOGC macro it is already provided.The helper class
ofmtbufstreamwas provided for any intermediate formatting. It's mainly a wrapper overstd::stringstream, while all string-like classes are written directly to the stream (bypass formatting), while all other types (mainly numeric) are passed throughfmtwith default formatting. Formatting is done by anotherstd::stringstreaminsidefmt_sender_proxy, which is then copied buffer-to-buffer to thestd::stringstreamin theofmtbufstreamclass. Theoperator<<is still in use here for C++03-based code, and for C++11-based code there's additionally theprintfunction, which does the same:It was chosen to have
fmtcwith manipulators implemented as its methods in order to minimize namespace pollution. This allows also to create a variable for a shortcut name of format configuration to be then applied in multiple following calls offmt. Symbol names introduced here:fmt: forced formatting function (returns the value-wrapping proxy to apply formatting when sent to the stream)fmts: like fmt, but returns the formatted value asstd::stringfmtc: format configuration structureofmtbufstream: format handler for multiple argumentsofmtrefstream: format handler as a wrapper overstd::ostreamclassfmtcat: formats all arguments one by one and returns everything asstd::stringBeside this solution, there were two others so far tried:
snprintffunction and crafts the format string out of the formatter structure - [core] New formatting implementation using SFMT for the logging system #2955This solution, out of all that were tried, shows the lowest CPU usage.