-
Notifications
You must be signed in to change notification settings - Fork 851
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
[core] Setting up fmt with custom config structure for logging system #2964
Open
ethouris
wants to merge
48
commits into
Haivision:master
Choose a base branch
from
ethouris:dev-add-custom-fmt-for-logging
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[core] Setting up fmt with custom config structure for logging system #2964
ethouris
wants to merge
48
commits into
Haivision:master
from
ethouris:dev-add-custom-fmt-for-logging
Conversation
This file contains 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
…pdated sfmt implementation
…adowed local variables
ethouris
changed the title
[core] Setting up fmt with iomanip for logging system
[core] Setting up fmt with custom config structure for logging system
Jul 18, 2024
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_proxy
with a helper functionfmt
so that nondefault formatting can be used in place. All intermediate formatting is done usingstd::ostringstream
orstd::stringstream
class.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
,b
in the form like:17-0001dead-42
usingprintf
you need:And in the standard iostream, you'd have to do the following:
With this ofmt facility the same can be written simply as:
This above can't be used directly without overloading the
operator <<
withfmt_sender_proxy
, but this is here available for the LOGC macro. The helper classofmtstream
was provided, which is mainly a wrapper aroundstd::stringstream
, but it makes all string-like types bypass the formatting facilities, while all other types (mainly numeric) are passed throughfmt
with default formatting. Formatting is done by anotherstd::stringstream
insidefmt_sender_proxy
, which is then copied buffer-to-buffer to thestd::stringstream
in theofmtstream
class. Theoperator<<
is still in use here for C++03-based code, and for C++11-based code there's additionally theprint
function, which does the same:The
fmtc
structure was used because it minimizes scope of the manipulator names, as well as allows to create a variable with format configuration to be then applied in multiple following calls offmt
. Symbol names introduced here:fmt
: forced formatting functionfmtc
: format configuration structureofmtstream
: format handler for multiple argumentsfmtcat
: formats all arguments one by one and returns everything asstd::string
TO CONSIDER: Maybe
ofmtbufstream
would be a better name for this one so thatofmtstream
can be used to wrap anystd::ostream
.Beside this solution, there were two others so far tried:
snprintf
function 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.