Skip to content

fix: Fixed the console logs flushing logic. - #18

Merged
ajeetsinghyadav merged 6 commits into
mainfrom
VNE_RHI_FLUSH_FIX
May 17, 2026
Merged

ajeetsinghyadav merged 6 commits into
mainfrom
VNE_RHI_FLUSH_FIX

Conversation

@ajeetsinghyadav

@ajeetsinghyadav ajeetsinghyadav commented May 17, 2026 •

Copy link
Copy Markdown
Member
  • Updated vnecmake and vnecommon submodule references to the latest commits.
  • Enhanced CMakeLists.txt to allow optional use of system-installed Google Test, with fallback to bundled version if not found, improving flexibility in test environment setup.

Summary by CodeRabbit

  • Bug Fixes

    • Error-level messages now go to stderr; other levels go to stdout.
    • Console flushing behavior changed: logs are written without per-call flush; flushed via the sink's flush path.
  • Chores

    • Updated internal dependencies and submodules.
    • Removed workspace editor config.
    • Improved test infrastructure and console-output capture and test harness configuration.

Review Change Stack

- Deleted .vscode/settings.json to eliminate outdated IDE settings.
- Removed unused logo files: vertexnova_logo_medallion_banner.png, vertexnova_logo_medallion_banner.svg, and vertexnova_logo_medallion_with_text.png to clean up the assets directory.
- Updated ConsoleLogSink to direct error and fatal logs to stderr, while other logs go to stdout.
- Ensured immediate visibility of logs by flushing the output streams after each write.
- Refactored test setup to capture both stdout and stderr for comprehensive log testing.
- Renamed CoutRedirect to StreamRedirect to better reflect functionality for both std::cout and std::cerr.
- Updated test setup to capture both stdout and stderr outputs.
- Introduced clearCapturedOutput() method for resetting captured output, improving test clarity and maintainability.
- Refactored output verification in tests to utilize capturedConsoleOutput() for consistency.
…r Google Test

- Updated vnecmake and vnecommon submodule references to the latest commits.
- Enhanced CMakeLists.txt to allow optional use of system-installed Google Test, with fallback to bundled version if not found, improving flexibility in test environment setup.
Copilot AI review requested due to automatic review settings May 17, 2026 17:08
@ajeetsinghyadav ajeetsinghyadav self-assigned this May 17, 2026
@coderabbitai

coderabbitai Bot commented May 17, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ee73e973-5a96-46dd-8d59-ea107b6d14aa

📥 Commits

Reviewing files that changed from the base of the PR and between ce6080c and e8769f0.

📒 Files selected for processing (5)
  • src/vertexnova/logging/core/console_log_sink.cpp
  • tests/CMakeLists.txt
  • tests/core/console_log_sink_test.cpp
  • tests/logging_system_test.cpp
  • tests/stream_redirect.h
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/CMakeLists.txt
  • src/vertexnova/logging/core/console_log_sink.cpp
  • tests/core/console_log_sink_test.cpp
  • tests/logging_system_test.cpp

📝 Walkthrough

Walkthrough

This PR routes error-and-higher logs to stderr and other levels to stdout; removes per-call flushing from log (flush() now flushes both streams); adds a StreamRedirect RAII helper for tests to capture both streams; updates tests and tests/CMakeLists.txt for dual-stream capture and flexible GTest resolution.

Changes

Console Logging stderr/stdout Split and Test Adaptation

Layer / File(s) Summary
Dependency and Submodule Updates
cmake/vnecmake, deps/internal/vnecommon
cmake/vnecmake and deps/internal/vnecommon submodule references are advanced to new commit SHAs.
Core Console Sink stdout/stderr Split and Flush API
src/vertexnova/logging/core/console_log_sink.cpp
ConsoleLogSink::log builds an output string and writes levels >= LogLevel::eError to std::cerr, others to std::cout. Per-call flush was removed; ConsoleLogSink::flush flushes both streams.
GoogleTest Dependency Resolution and Test Target Config
tests/CMakeLists.txt
Adds VNE_USE_SYSTEM_GTEST option; conditional resolution: system find_package(GTest) (when enabled) → bundled deps/external/googletest → FetchContent googletest v1.14.0. Adds stream_redirect.h to test includes and sets CTest WORKING_DIRECTORY to the test binary directory.
Test Infrastructure: StreamRedirect RAII Helper
tests/stream_redirect.h
Adds StreamRedirect class that swaps a std::ios's rdbuf to capture output and restores it on destruction; copying is deleted.
Test Fixtures and Assertions Updated for Dual-Stream Capture
tests/core/console_log_sink_test.cpp, tests/logging_system_test.cpp, tests/core/text_color_test.cpp
Tests now redirect both std::cout and std::cerr into separate buffers using StreamRedirect; fixtures select/clear buffers based on LogLevel and assertions read combined or level-specific captured output. TextColorTest::SelfAssignment uses an explicit self-reference assignment.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit's refrain on separated streams:
Error hops straight to stderr's door,
Gentle logs skip out stdout's floor,
Tests redirect with RAII grace,
Buffers checked in their proper place,
A tidy hop across the logging space.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.04% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: Fixed the console logs flushing logic.' accurately describes the main change: refactoring console output flushing in ConsoleLogSink to delegate flushing to the flush() method instead of doing it inline.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch VNE_RHI_FLUSH_FIX

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates console logging behavior and related tests, while also changing test dependency setup and removing repository assets/settings.

Changes:

  • Routes error/fatal console logs to stderr, flushes console streams, and updates tests to capture both stdout and stderr.
  • Adds a CMake option for system Google Test with bundled fallback and sets the test working directory.
  • Removes a VS Code settings file and an SVG logo asset.

Reviewed changes

Copilot reviewed 8 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/vertexnova/logging/core/console_log_sink.cpp Updates console output routing and flushing behavior.
tests/core/console_log_sink_test.cpp Adjusts console sink tests to capture stdout/stderr.
tests/logging_system_test.cpp Updates logging system tests to capture both console streams.
tests/core/text_color_test.cpp Changes self-assignment test to avoid direct self-assignment syntax.
tests/CMakeLists.txt Adds configurable Google Test selection and test working directory.
.vscode/settings.json Removes workspace settings.
icons/vertexnova_logo_medallion_banner.svg Removes SVG logo asset.
Comments suppressed due to low confidence (1)

.vscode/settings.json:1

  • Deleting the repository VS Code workspace settings is outside the scope described by the PR title/description. Please update the PR description with the rationale for removing these shared development settings, or revert this file deletion if it was not intended.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
tests/logging_system_test.cpp (1)

36-51: ⚡ Quick win

Replace raw owning pointers with std::unique_ptr.

The test fixture uses raw owning pointers with manual new/delete, which violates RAII best practices. As per coding guidelines, prefer std::unique_ptr for ownership to ensure automatic cleanup and exception safety.

♻️ Proposed refactor
     void SetUp() override {
-        cout_redirect_ = new StreamRedirect(std::cout, cout_buffer_.rdbuf());
-        cerr_redirect_ = new StreamRedirect(std::cerr, cerr_buffer_.rdbuf());
+        cout_redirect_ = std::make_unique<StreamRedirect>(std::cout, cout_buffer_.rdbuf());
+        cerr_redirect_ = std::make_unique<StreamRedirect>(std::cerr, cerr_buffer_.rdbuf());
     }
 
     void TearDown() override {
         // Remove the test directory and clean up
         try {
             std::filesystem::remove_all(kTestDir);
         } catch (const std::exception& e) {
             std::cerr << "Exception during TearDown(): " << e.what() << std::endl;
         }
 
-        delete cout_redirect_;
-        delete cerr_redirect_;
+        cout_redirect_.reset();
+        cerr_redirect_.reset();
     }
    protected:
     std::stringstream cout_buffer_;
     std::stringstream cerr_buffer_;
-    StreamRedirect* cout_redirect_ = nullptr;
-    StreamRedirect* cerr_redirect_ = nullptr;
+    std::unique_ptr<StreamRedirect> cout_redirect_;
+    std::unique_ptr<StreamRedirect> cerr_redirect_;
 };

Also applies to: 63-67

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/logging_system_test.cpp` around lines 36 - 51, Replace the raw owning
pointers cout_redirect_ and cerr_redirect_ in the test fixture with
std::unique_ptr to enforce RAII: change their declarations to
std::unique_ptr<StreamRedirect>, initialize them in SetUp() using
std::make_unique<StreamRedirect>(...) instead of new, and remove the explicit
delete calls from TearDown(); ensure StreamRedirect construction and destruction
behavior remains the same and update any other occurrences (e.g., lines around
the other fixture use at 63-67) to use the unique_ptr API (->) where needed.
tests/CMakeLists.txt (1)

30-30: ⚡ Quick win

Remove unused variable.

The variable _vne_use_bundled_gtest is set but never used in the rest of the file. This is dead code and should be removed.

🧹 Proposed fix
-set(_vne_use_bundled_gtest FALSE)
-
 if(VNE_USE_SYSTEM_GTEST)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/CMakeLists.txt` at line 30, Remove the dead CMake variable assignment
for _vne_use_bundled_gtest by deleting the line set(_vne_use_bundled_gtest
FALSE); confirm there are no other references to _vne_use_bundled_gtest
elsewhere and if the intent was to expose a configurable option, replace it with
an option(...) or set a documented cache variable instead of the unused local
set call.
tests/core/console_log_sink_test.cpp (1)

38-49: ⚡ Quick win

Replace raw owning pointers with std::unique_ptr.

The test fixture uses raw owning pointers with manual new/delete, which violates RAII best practices and increases risk if exceptions occur during setup. As per coding guidelines, prefer std::unique_ptr for ownership.

♻️ Proposed refactor
     void SetUp() override {
         // Force colors on for testing (tests run without TTY)
         log::setColorEnabled(true);
-        cout_redirect_ = new StreamRedirect(std::cout, cout_buffer_.rdbuf());
-        cerr_redirect_ = new StreamRedirect(std::cerr, cerr_buffer_.rdbuf());
+        cout_redirect_ = std::make_unique<StreamRedirect>(std::cout, cout_buffer_.rdbuf());
+        cerr_redirect_ = std::make_unique<StreamRedirect>(std::cerr, cerr_buffer_.rdbuf());
     }
 
     void TearDown() override {
-        delete cout_redirect_;
-        delete cerr_redirect_;
+        cout_redirect_.reset();
+        cerr_redirect_.reset();
         log::setColorEnabled(true);
     }
    protected:
     std::stringstream cout_buffer_;
     std::stringstream cerr_buffer_;
-    StreamRedirect* cout_redirect_ = nullptr;
-    StreamRedirect* cerr_redirect_ = nullptr;
+    std::unique_ptr<StreamRedirect> cout_redirect_;
+    std::unique_ptr<StreamRedirect> cerr_redirect_;
 };

Also applies to: 56-60

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/core/console_log_sink_test.cpp` around lines 38 - 49, Replace the raw
owning pointers cout_redirect_ and cerr_redirect_ with
std::unique_ptr<StreamRedirect>; update their declarations accordingly,
construct them with std::make_unique in SetUp (using cout_buffer_.rdbuf() and
cerr_buffer_.rdbuf()), and remove the manual delete calls in TearDown (allow
unique_ptr to destroy automatically, or call reset() if explicit release is
desired); keep calls to log::setColorEnabled(true) and ensure StreamRedirect
usage and members (cout_buffer_, cerr_buffer_) remain unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/logging_system_test.cpp`:
- Around line 17-29: Extract the duplicated StreamRedirect RAII class into a
single shared test header (e.g., create tests/stream_redirect.h) and replace the
inline definitions in console_log_sink_test.cpp and logging_system_test.cpp with
an `#include` of that header; ensure the new header contains the StreamRedirect
definition (constructor, destructor, private members) with proper include guards
or pragma once and the same behavior, then remove the duplicate class
declarations from both test files and update their includes to reference the
shared header so they reuse the single implementation.
- Line 46: The TearDown() exception handler currently writes to std::cerr while
the test framework has redirected std::cerr, so the message will be captured
instead of appearing on the real console; update the handler in TearDown() to
write the error directly to the OS stderr (e.g., use a low-level write to
STDERR_FILENO or call fprintf(stderr, ...) after restoring the original stream)
and include e.what() in that write so the message goes to the real terminal
rather than the test buffer.

---

Nitpick comments:
In `@tests/CMakeLists.txt`:
- Line 30: Remove the dead CMake variable assignment for _vne_use_bundled_gtest
by deleting the line set(_vne_use_bundled_gtest FALSE); confirm there are no
other references to _vne_use_bundled_gtest elsewhere and if the intent was to
expose a configurable option, replace it with an option(...) or set a documented
cache variable instead of the unused local set call.

In `@tests/core/console_log_sink_test.cpp`:
- Around line 38-49: Replace the raw owning pointers cout_redirect_ and
cerr_redirect_ with std::unique_ptr<StreamRedirect>; update their declarations
accordingly, construct them with std::make_unique in SetUp (using
cout_buffer_.rdbuf() and cerr_buffer_.rdbuf()), and remove the manual delete
calls in TearDown (allow unique_ptr to destroy automatically, or call reset() if
explicit release is desired); keep calls to log::setColorEnabled(true) and
ensure StreamRedirect usage and members (cout_buffer_, cerr_buffer_) remain
unchanged.

In `@tests/logging_system_test.cpp`:
- Around line 36-51: Replace the raw owning pointers cout_redirect_ and
cerr_redirect_ in the test fixture with std::unique_ptr to enforce RAII: change
their declarations to std::unique_ptr<StreamRedirect>, initialize them in
SetUp() using std::make_unique<StreamRedirect>(...) instead of new, and remove
the explicit delete calls from TearDown(); ensure StreamRedirect construction
and destruction behavior remains the same and update any other occurrences
(e.g., lines around the other fixture use at 63-67) to use the unique_ptr API
(->) where needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c85a09dc-924e-4240-9509-85071faa83c0

📥 Commits

Reviewing files that changed from the base of the PR and between c468219 and ce6080c.

⛔ Files ignored due to path filters (3)
  • icons/vertexnova_logo_medallion_banner.png is excluded by !**/*.png
  • icons/vertexnova_logo_medallion_banner.svg is excluded by !**/*.svg
  • icons/vertexnova_logo_medallion_with_text.png is excluded by !**/*.png
📒 Files selected for processing (8)
  • .vscode/settings.json
  • cmake/vnecmake
  • deps/internal/vnecommon
  • src/vertexnova/logging/core/console_log_sink.cpp
  • tests/CMakeLists.txt
  • tests/core/console_log_sink_test.cpp
  • tests/core/text_color_test.cpp
  • tests/logging_system_test.cpp
💤 Files with no reviewable changes (1)
  • .vscode/settings.json

Comment thread tests/logging_system_test.cpp Resolved
Comment thread tests/logging_system_test.cpp Resolved
…ging functionality

- Removed direct flushing of stdout and stderr in ConsoleLogSink, delegating flushing to ConsoleLogSink::flush() for better control.
- Introduced a new StreamRedirect class for capturing console output, replacing raw pointers with std::unique_ptr for improved memory management.
- Updated test setup and teardown processes to utilize the new StreamRedirect class, enhancing clarity and safety in output redirection.
…s.txt

- Deleted the variable setting for using bundled Google Test, streamlining the CMake configuration for test dependencies.
@ajeetsinghyadav
ajeetsinghyadav merged commit 9e20c66 into main May 17, 2026
17 checks passed
@ajeetsinghyadav
ajeetsinghyadav deleted the VNE_RHI_FLUSH_FIX branch May 17, 2026 17:23
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.

2 participants