feat(logging): add unified logging macros and helper functions (#175)#182
Merged
Conversation
…port This commit introduces inline logging functions that integrate with GlobalLoggerRegistry and automatically capture source location information at the call site. Key features implemented: - Level-specific functions: log_trace(), log_debug(), log_info(), log_warning(), log_error(), log_critical() - Automatic source_location capture (C++17/C++20 compatible) - Support for default logger and named loggers - Utility functions: is_enabled(), flush() - All functions are inline for zero overhead when logging is disabled The log_functions.h header provides: - log(level, message): Log to default logger - log(level, message, logger): Log to specific logger instance - log(level, message, logger_name): Log to named logger from registry - Level-specific convenience functions with source location capture Thread Safety: - All functions are thread-safe - Source location capture happens at compile-time - Logger retrieval uses thread-safe GlobalLoggerRegistry Updated common.h to include new logging headers for easy access. Refs: #175
…and macros This commit adds unit tests covering all aspects of the unified logging implementation, ensuring correctness and thread safety. Test categories implemented: 1. Basic Logging Function Tests: - Log message with correct level - Source location automatic capture - All log levels (trace, debug, info, warning, error, critical) 2. Named Logger Tests: - Logging to named loggers via registry - Logging to specific logger instances - Named logger with level-specific functions 3. Level Filtering Tests: - Log level filtering behavior - is_enabled() function correctness - Named logger level checking 4. Flush Tests: - Default logger flush - Named logger flush 5. Macro Tests: - LOG_* macros for all levels - LOG_*_TO macros for named loggers - LOG_IF conditional logging - LOG_FLUSH and LOG_IS_ENABLED utilities 6. Legacy Compatibility Tests: - THREAD_LOG_* macros redirect to LOG_* - All legacy levels work correctly 7. NullLogger Fallback Tests: - Unregistered logger returns NullLogger - No default logger uses NullLogger 8. Thread Safety Tests: - Concurrent logging to default logger - Concurrent logging to multiple loggers 9. String Compatibility Tests: - std::string_view input - const char* input - std::string input All 30 tests pass successfully. Refs: #175
This commit updates documentation to reflect the new unified logging functions and macros introduced in Issue #175. API Reference updates: - Added "Unified Logging" section with complete API documentation - Documented log_functions.h with all function signatures - Documented log_macros.h with all macro definitions - Added usage examples for both functions and macros - Documented compile-time level filtering via KCENON_MIN_LOG_LEVEL - Documented legacy THREAD_LOG_* compatibility macros - Updated version to 2.1 and last updated date Changelog updates: - Added entry for unified logging functions and macros - Listed all new features: - Level-specific functions with source_location - Standard LOG_* macros - Named logger LOG_*_TO macros - Conditional LOG_IF macros - Compile-time level filtering - Legacy THREAD_LOG_* compatibility Refs: #175
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #182 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 13 13
Lines 1582 1582
=====================================
Misses 1582 1582
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This commit fixes a compilation error on Clang where calls like
`log_info("message", "logger_name")` were ambiguous between:
- `log_info(string_view message, source_location loc = current())`
- `log_info(string_view message, string logger_name, source_location loc = current())`
The issue occurred because C string literals can implicitly convert to both
source_location (via default parameter) and std::string, causing Clang to
report "call to 'log_info' is ambiguous".
Solution:
- Renamed named logger functions from `log_*()` to `log_*_to()`
- Changed parameter order to `log_*_to(logger_name, message)`
- This eliminates overload ambiguity by using distinct function names
API changes:
- Old: `log_info("msg", "logger")` - REMOVED (ambiguous)
- New: `log_info_to("logger", "msg")` - ADDED (unambiguous)
The LOG_*_TO macros continue to work with the same syntax:
`LOG_INFO_TO("logger", "msg")` - unchanged interface
Updated:
- log_functions.h: Renamed functions with "_to" suffix
- log_macros.h: Updated macro implementations
- Tests: Updated to use new function names
- API documentation: Reflected new function signatures
Refs: #175
5 tasks
kcenon
added a commit
that referenced
this pull request
Apr 13, 2026
…#182) * feat(logging): add unified logging functions with source_location support This commit introduces inline logging functions that integrate with GlobalLoggerRegistry and automatically capture source location information at the call site. Key features implemented: - Level-specific functions: log_trace(), log_debug(), log_info(), log_warning(), log_error(), log_critical() - Automatic source_location capture (C++17/C++20 compatible) - Support for default logger and named loggers - Utility functions: is_enabled(), flush() - All functions are inline for zero overhead when logging is disabled The log_functions.h header provides: - log(level, message): Log to default logger - log(level, message, logger): Log to specific logger instance - log(level, message, logger_name): Log to named logger from registry - Level-specific convenience functions with source location capture Thread Safety: - All functions are thread-safe - Source location capture happens at compile-time - Logger retrieval uses thread-safe GlobalLoggerRegistry Updated common.h to include new logging headers for easy access. Refs: #175 * test(logging): add comprehensive tests for unified logging functions and macros This commit adds unit tests covering all aspects of the unified logging implementation, ensuring correctness and thread safety. Test categories implemented: 1. Basic Logging Function Tests: - Log message with correct level - Source location automatic capture - All log levels (trace, debug, info, warning, error, critical) 2. Named Logger Tests: - Logging to named loggers via registry - Logging to specific logger instances - Named logger with level-specific functions 3. Level Filtering Tests: - Log level filtering behavior - is_enabled() function correctness - Named logger level checking 4. Flush Tests: - Default logger flush - Named logger flush 5. Macro Tests: - LOG_* macros for all levels - LOG_*_TO macros for named loggers - LOG_IF conditional logging - LOG_FLUSH and LOG_IS_ENABLED utilities 6. Legacy Compatibility Tests: - THREAD_LOG_* macros redirect to LOG_* - All legacy levels work correctly 7. NullLogger Fallback Tests: - Unregistered logger returns NullLogger - No default logger uses NullLogger 8. Thread Safety Tests: - Concurrent logging to default logger - Concurrent logging to multiple loggers 9. String Compatibility Tests: - std::string_view input - const char* input - std::string input All 30 tests pass successfully. Refs: #175 * docs(logging): update API reference and changelog for unified logging This commit updates documentation to reflect the new unified logging functions and macros introduced in Issue #175. API Reference updates: - Added "Unified Logging" section with complete API documentation - Documented log_functions.h with all function signatures - Documented log_macros.h with all macro definitions - Added usage examples for both functions and macros - Documented compile-time level filtering via KCENON_MIN_LOG_LEVEL - Documented legacy THREAD_LOG_* compatibility macros - Updated version to 2.1 and last updated date Changelog updates: - Added entry for unified logging functions and macros - Listed all new features: - Level-specific functions with source_location - Standard LOG_* macros - Named logger LOG_*_TO macros - Conditional LOG_IF macros - Compile-time level filtering - Legacy THREAD_LOG_* compatibility Refs: #175 * fix(logging): resolve function overload ambiguity with Clang compiler This commit fixes a compilation error on Clang where calls like `log_info("message", "logger_name")` were ambiguous between: - `log_info(string_view message, source_location loc = current())` - `log_info(string_view message, string logger_name, source_location loc = current())` The issue occurred because C string literals can implicitly convert to both source_location (via default parameter) and std::string, causing Clang to report "call to 'log_info' is ambiguous". Solution: - Renamed named logger functions from `log_*()` to `log_*_to()` - Changed parameter order to `log_*_to(logger_name, message)` - This eliminates overload ambiguity by using distinct function names API changes: - Old: `log_info("msg", "logger")` - REMOVED (ambiguous) - New: `log_info_to("logger", "msg")` - ADDED (unambiguous) The LOG_*_TO macros continue to work with the same syntax: `LOG_INFO_TO("logger", "msg")` - unchanged interface Updated: - log_functions.h: Renamed functions with "_to" suffix - log_macros.h: Updated macro implementations - Tests: Updated to use new function names - API documentation: Reflected new function signatures Refs: #175
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.
Summary
This PR implements Issue #175, adding unified logging macros and helper functions that provide a consistent logging interface across all subsystems with automatic source_location capture.
Key Features
1. Inline Logging Functions (
log_functions.h)log_trace(),log_debug(),log_info(),log_warning(),log_error(),log_critical()is_enabled(),flush()2. Logging Macros (
log_macros.h)LOG_TRACE,LOG_DEBUG,LOG_INFO,LOG_WARNING,LOG_ERROR,LOG_CRITICALLOG_*_TO(logger_name, msg)LOG_IF(level, msg)for avoiding expensive message construction when level is disabledKCENON_MIN_LOG_LEVELTHREAD_LOG_*macros redirect toLOG_*Files Changed
include/kcenon/common/logging/log_functions.hinclude/kcenon/common/logging/log_macros.hinclude/kcenon/common/common.htests/log_functions_test.cpptests/CMakeLists.txtdocs/API_REFERENCE.mddocs/CHANGELOG.mdUsage Examples
Test Plan
common_log_functions_test)Dependencies
Closes #175