-
Notifications
You must be signed in to change notification settings - Fork 92
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
Explicitly delimit EOM for logging #820
Comments
Thanks for the suggestions @jwnimmer-tri. This is definitely something we want to address. My initial thought is to go with the |
Agreed that would be a nice alternative to #351. And if it works well on SDFormat, we should consider moving all of Ignition to spdlog. |
In the context of a more disruptive change like porting to spdlog, I'd like to underline my "Additional context" paragraph from the original posting. A parsing library has no business printing to the console in the first place -- we should always use the For convenience, maybe the library could offer a "just keep it simple and display the errors to cerr anyway" sugar, but we don't need spdlog for that, we just need a "Dump a |
I agree that we should use the |
Many uses of If the answer is that they should all be using the There are no calls to I think that calls to In short, I don't buy this statement:
Can you link to any example in the code that's emitting an informational message to the console, but that should never actually be communicated to the calling code in a structured way beyond the console? I couldn't find any. |
If the user chooses |
Yes, I think so. Users who want something more specific can parse and receive the I haven't tried to weave these specific ideas in the current API, so there are probably a few loose ends still to design. I just have the one big-picture idea: it's fine if we have a Console class to help with streaming messages to the terminal, but it can only exist at the very outermost / highest layer of the parsing code. The parsing code should to produce a structured list of errors (of varying severity). If the user doesn't specify what to do with that list once the parsing is complete, then it's fine to just print it out. The only problem with printing is having the lower-layer code do it outside of the caller's control. |
Currently, the way Both approaches would incur significant changes in API and general behavior. For example, if we added the ability to represent varying severity in |
We have started (#939 being the first PR) adding |
Since we don't have a separate data structure for warnings, for now, the plan is to handle them by updating all
|
Per VC, remaining work is 2 PRs to be filed soon. |
Desired behavior
The Console (i.e., logging) abstraction in libsdformat currently follows the semantics of something like
std::cerr
-- a simple text stream where the call sites conclude each call with a newline (sdferr << ... << "\n";
). Even if we switch to use the ignition-common console per #351, it still currently embodies the same abstraction.However, in a lot of production code, log message telemetry is not just a dedicated console read by human eyes -- it is recorded in a structured form, sent over the network, and/or otherwise treated on a message basis rather a stream basis.
My request here is to change the Console to use the same semantics -- where there is a clear "end of message" demarcation.
Several C++ logging frameworks (e.g., log4cpp) do this by using the logger lifetime to conclude the message. My patch file in RobotLocomotion/drake#16348 shows an example of this. The
Console::ColorMsg
function returns a short-lived stream by-value, instead of a long-lived stream by-reference. When the statement ends, the temporary is destroyed, and in its destructor the message is posted.Another technique is what
spdlog
does -- the user makes a single function call to log, passing both the format string and all of the arguments all at once. This would be a more significant rewrite of the calling-code than the stream lifetime change, but would be a better choice in case theConsole
needed to be used from languages beyond just C++.Alternatives considered
A different design would be to keep the streaming API unchanged, but to have the implementation monitor the character buffer insertions for newlines, and replace all newlines with EOM / log posting. I am not a fan of that design, because it removes the ability for a single log message to have embedded newlines, which I've often found to be useful.
Additional context
For sdformat in particular, as I've explained in #334 (comment) the library should never be printing to any console anyway. The calls to parse should have a structured way to report errors, and should be silent on
cerr
. The current design and use ofsdf::Error
gets us most of the way there, but there are still a ton of places in the library code that stream tosdferr
(orsdfwarn
, etc.) instead of appending ansdf::Error
. If we fixed that problem instead, then we could delete the sdformat-specificConsole
class and this whole discussion here is moot (though would still apply to the ignition-common logging API design).The text was updated successfully, but these errors were encountered: