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

Make JLogMessage consistent with JStreamLog #390

Merged
merged 4 commits into from
Dec 5, 2024

Conversation

nathanwbrei
Copy link
Collaborator

  • Adds support for appending log metadata to each line of a multi-line log message
  • A special log message terminator is no longer needed: flushing to the output stream is handled by the JLogMessage destructor
  • JLogMessage now supports stream manipulators, most notably std::endl
  • In principle, jout, jerr, and _DBG_ can now use JLogMessage under the hood.

JLogMessage flushes its output when it receives an End{} token. This is the worst of all worlds because it
1. Prevents us from appending metadata on each line of a multiline message like JStreamLog
2. Prevents us from being able to use it with output-agnostic methods like `void PrintUsefulOutput(std::ostream&)`
3. Ties us to always using C++ stream operators
4. Doesn't let us use C++ stream manipulators
5. Can't be used as a replacement for `jout` and `_DBG_`, which use std::endl and _don't_ have an end-of-message token

The replacement extends `std::stringstream` instead of wrapping it. It flushes on destruction, and users may optionally trigger a flush by streaming in a special flush token. This solves the problems listed above and should be sufficient to replace the existing JLogMessage, jout, jerr, _DBG_, and JStreamLog.
This is for the sake of having exactly one way of doing things. Flush complicates the semantics and implementation of JLogMessage without adding any needed functionality. Furthermore it is conceptually confused since a std::stringstream already has a flush() method which does not do what Flush() does. The pared-down JLogMessage is easy to explain as "std::ostringstream with a logger-specific line prefix and RAII for printing its contents to the log".
@nathanwbrei nathanwbrei merged commit c216891 into master Dec 5, 2024
9 checks passed
@nathanwbrei nathanwbrei deleted the nbrei_logger_improvements branch December 5, 2024 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant