Skip to content

Added new business functions#2

Open
Gotnhub wants to merge 1 commit into
v1.xfrom
feat/my-change-km
Open

Added new business functions#2
Gotnhub wants to merge 1 commit into
v1.xfrom
feat/my-change-km

Conversation

@Gotnhub

@Gotnhub Gotnhub commented Mar 5, 2026

Copy link
Copy Markdown
Owner

Summary

This PR introduces a new sink, business_rotating_sink, which routes log messages to different rotating log files based on a business tag/identifier. Each business has its own independent rotation state (max file size 30MB, max 3 rotated files kept). The implementation follows spdlog’s existing sink patterns (mt/st variants, header + -inl.h split), and includes unit tests integrated into the test build.

Motivation

In applications where multiple business modules share the same logging infrastructure, it’s often necessary to:

  • write different business logs into different files
  • keep separate rotation per business
  • control disk usage (file size + number of historical files)
  • select the target log file by passing a business tag when logging

Changes

Added

  • include/spdlog/sinks/business_rotating_sink.h
    Declares business_rotating_sink and factory helpers.
  • include/spdlog/sinks/business_rotating_sink-inl.h
    Inline implementation for template code (matches spdlog conventions).
  • tests/test_business_rotating_sink.cpp
    New unit tests (8 test cases).

Modified

  • src/file_sinks.cpp
    Adds template instantiations for business_rotating_sink (consistent with existing file sinks).
  • tests/CMakeLists.txt
    Registers the new test source in the test target.
  • tests/includes.h
    Adds the required include for the new sink header.

Implementation Notes

  • Template-based design with business_rotating_sink_mt and business_rotating_sink_st, aligning with spdlog’s mt/st naming and threading model.
  • One rotating_file_sink per business tag: each tag maps to its own rotating sink instance, maintaining independent file names and rotation state.
  • Locking / deadlock avoidance: sink_it_ is implemented to avoid re-acquiring locks and prevents nested locking scenarios that could lead to deadlocks.
  • Uses the standard *.h + *-inl.h split to keep template implementation in headers while preserving readability and build behavior.

Testing

  • Business sink tests: 8 test cases / 32 assertions (tag: [business_rotating_sink])
  • Full test suite: 189 test cases / 637 assertions — all passed

Notes

This is an additive feature and should not affect existing sinks or behavior.

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