Skip to content

Provide a shared scoped ostream logger utility for tests #808

Description

@coderabbitai

Summary

Some tests replace the global spdlog default logger with an ostream_sink_mt that references a local std::ostringstream. If the test does not restore the previous default logger before the stream is destroyed, later spdlog calls can access a destroyed stream.

Required changes

  • Add a common test-only ostream-logging utility for tests that need to inspect log output.
  • The utility must save the existing spdlog::default_logger() before it installs a test logger.
  • The utility must restore the saved default logger with scope-bound cleanup before its std::ostringstream is destroyed.
  • Update tests that need ostream logging to use this common utility. Do not re-implement local logger-installation helpers in each test.

Rationale

spdlog::set_default_logger(...) changes global process state. A shared scoped utility prevents dangling ostream_sink_mt stream references and gives all tests the same cleanup behavior.

Affected areas

  • Test logging helpers or test support module.
  • test/accumulator_test.cpp (use_ostream_logger).
  • Other tests that replace the global spdlog default logger.

Acceptance criteria

  • A reusable scoped ostream-logging utility exists for test code.
  • The utility restores the prior default logger before its backing stream is destroyed.
  • test/accumulator_test.cpp uses the common utility.
  • Other tests that require ostream logging use the same utility instead of duplicate local implementations.

Backlinks

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions