Improve semantic text log formatting and restore terminal colors#182
Closed
VolkerChristian wants to merge 4 commits into
Closed
Improve semantic text log formatting and restore terminal colors#182VolkerChristian wants to merge 4 commits into
VolkerChristian wants to merge 4 commits into
Conversation
### Motivation
- Make the default semantic **text** output human-friendly by replacing the old positional layout with a compact tagged format, restore terminal coloring for stdout text, and keep JSON/file output machine-friendly and plain.
- Avoid ugly duplicated positional fields and make optional semantic fields explicit, properly quoted/escaped, and make multiline messages visibly part of the preceding record.
### Description
- Replace positional text formatter with a compact tagged format and add a color-aware overload: added `formatText(const LogRecord&, bool colorEnabled)` and kept `formatText(const LogRecord&)` as the plain variant; implement 3-letter level labels, compact `origin/boundary` rendering, `key=value` optional fields, quoting/escaping and multiline continuation prefixes (see `src/log/SemanticLogger.cpp` / `src/log/SemanticLogger.h`).
- Emit both plain and colored text to the backend so the backend can route plain/plain-to-file and colored-to-stdout without leaking ANSI into file/JSON: `Logger::emitSemantic` now chooses JSON vs text and passes `(plain, colored)` to the backend, and `SpdlogBackend` now accepts `emitSemantic(level, plainRecord, coloredRecord)` and emits colored text only to stdout when colors are enabled and plain text always to file (`src/log/Logger.cpp`, `src/log/detail/SpdlogBackend.{h,cpp}`).
- Preserve JSON output completely by calling `formatJsonV1(record)` unchanged and sending the identical string for both plain/colored backend paths when JSON is selected.
- Respect existing color disabling: the backend uses the existing `disableColor` flag to decide whether semantic stdout uses colored or plain output; no new public CLI options added (`Logger::setDisableColor` / `Logger::getDisableColor()` remain authoritative).
- Packaging cleanup: exclude internal `detail` headers from public install by adding a `PATTERN "detail" EXCLUDE` to `src/log/CMakeLists.txt` so `src/log/detail/SpdlogBackend.h` is not installed as a public header.
- Tests: updated and expanded focused unit tests for the new text shape, quoting/escaping, multiline prefixing, color/no-ANSI expectations, level labels, optional field rendering, and the install rule; adjusted many migration tests to assert the compact `origin/boundary` rendering (tests under `tests/unit/log/*`).
### Testing
- Built and ran tests with SNODEC_BUILD_TESTS=ON and apps on: `cmake -S . -B cmake-build -DSNODEC_BUILD_TESTS=ON -DSNODEC_BUILD_APPS=ON` then `cmake --build cmake-build --parallel 2` and executed tests with `ctest --test-dir cmake-build -R "Log|Semantic|Logger" --output-on-failure` followed by a full `ctest --test-dir cmake-build --output-on-failure`.
- All exercised semantic/log related unit tests passed after the changes; the final test run completed with 100% of executed tests passing (the suite was also exercised end-to-end in the build environment described above).
…ckend API changes ### Motivation - Replace verbose legacy semantic text formatting with a compact, tag-style text formatter and add optional ANSI color styling for terminal stdout while keeping JSON output unchanged. - Allow the backend to receive both plain and colored semantic text so file output remains unstyled and console output may be colored when appropriate. - Hide internal headers from installs by excluding the `detail` directory from the public `install` rules. ### Description - Introduced a compact text formatter that emits 3-letter level labels, `framework/…` style origin/boundary, compact tagged key=value fields (with quoting/escaping when needed), multiline continuation prefixing, and an ANSI-styled variant; implemented in `SemanticLogger.cpp` as `formatTextRecord`, and exposed colored variant via `logger::detail::formatTextColored`. - Changed `Logger::emitSemantic` to branch on `LogManager::Format::Json` and to pass both plain and colored semantic text to the backend for non-JSON formats, or JSON for JSON format. - Updated `SpdlogBackend` API to accept `plainRecord` and `coloredRecord` in `emitSemantic`, added `semanticStdoutUsesColor()` to decide whether to emit colored text to stdout, and ensured file sinks always get plain (unstyled) text; adjusted header `SpdlogBackend.h` and implementation `SpdlogBackend.cpp` accordingly. - Adjusted `CMakeLists.txt` to exclude `detail` headers from the install by adding `PATTERN "detail" EXCLUDE` to the install `FILES_MATCHING` rule. - Updated many unit tests under `tests/unit/log` to match the new compact formatting and color/ANSI expectations and to assert the `detail` install exclusion. ### Testing - Ran the unit test suite for logging under `tests/unit/log` (updated tests) and verified the modified expectations for text, JSON, colored output presence/absence, and install rule; tests passed locally.
…te tests ### Motivation - Rework semantic text output to a more compact, tag-style format with optional ANSI coloring for terminal stdout while keeping file and JSON output plain. - Ensure framework/component/identity information is emitted by semantic records without duplicating connection names in call sites. - Prevent internal `detail` headers from being installed. ### Description - Introduce a new compact text formatter with quoted key=value fields, multiline continuation handling, 3-letter level labels, and ANSI color support via new `formatTextRecord`, `detail::formatTextColored`, and related helpers in `src/log/SemanticLogger.cpp` and expose `formatText` to use it for plain output. - Change `Logger::emitSemantic` to branch on `LogManager::format()` and send either JSON (`formatJsonV1`) or plain/colored text to the backend, and update `SpdlogBackend` to accept both `plainRecord` and `coloredRecord` and choose colored output for stdout only when appropriate via `semanticStdoutUsesColor`. - Remove duplicated connection-name prefixes from many `frameworkLog()` calls in HTTP client/server `SocketContext` files since semantic records now carry identity. - Exclude `detail` headers from the logger install rule in `src/log/CMakeLists.txt`. - Add a new test `SemanticIdentityMessagePolicyTest.cpp` and update numerous unit tests in `tests/unit/log` to reflect the new compact formatting, level labels, color behavior, and changed framework scope strings. ### Testing - Updated and executed the unit tests under `tests/unit/log` with expectations adjusted for the new text format and identity handling, and the test suite completed successfully. - Verified the new `SemanticIdentityMessagePolicyTest` runs as part of the unit tests and passes. - Confirmed that JSON output and legacy logging paths remain unstyled and preserve previous semantics via unit assertions.
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.
Motivation
Description
formatText(const LogRecord&, bool colorEnabled)and keptformatText(const LogRecord&)as the plain variant; implement 3-letter level labels, compactorigin/boundaryrendering,key=valueoptional fields, quoting/escaping and multiline continuation prefixes (seesrc/log/SemanticLogger.cpp/src/log/SemanticLogger.h).Logger::emitSemanticnow chooses JSON vs text and passes(plain, colored)to the backend, andSpdlogBackendnow acceptsemitSemantic(level, plainRecord, coloredRecord)and emits colored text only to stdout when colors are enabled and plain text always to file (src/log/Logger.cpp,src/log/detail/SpdlogBackend.{h,cpp}).formatJsonV1(record)unchanged and sending the identical string for both plain/colored backend paths when JSON is selected.disableColorflag to decide whether semantic stdout uses colored or plain output; no new public CLI options added (Logger::setDisableColor/Logger::getDisableColor()remain authoritative).detailheaders from public install by adding aPATTERN "detail" EXCLUDEtosrc/log/CMakeLists.txtsosrc/log/detail/SpdlogBackend.his not installed as a public header.origin/boundaryrendering (tests undertests/unit/log/*).Testing
cmake -S . -B cmake-build -DSNODEC_BUILD_TESTS=ON -DSNODEC_BUILD_APPS=ONthencmake --build cmake-build --parallel 2and executed tests withctest --test-dir cmake-build -R "Log|Semantic|Logger" --output-on-failurefollowed by a fullctest --test-dir cmake-build --output-on-failure.Codex Task