Skip to content

Conversation

konard
Copy link
Member

@konard konard commented Sep 11, 2025

Summary

Implements log level resetting functionality for FFI as requested in issue #12. The solution uses tracing_subscriber::reload::Handle with a global lazy static handle to provide dynamic log level management.

Key Features

  • Global reload handle: Uses once_cell::Lazy with Mutex<Option<reload::Handle>> to store the reload handle globally
  • Dynamic log level control: New FFI functions set_log_level() and reset_log_level() allow runtime log level changes
  • Thread-safe implementation: Uses mutex protection for the global handle
  • Comprehensive error handling: Proper validation and error reporting for invalid log levels
  • Backward compatibility: Maintains existing logging functionality while adding new features

Implementation Details

New FFI Functions

  • set_log_level(level: *const c_char) -> bool: Sets log level to specified string (e.g., "trace", "debug", "info", "warn", "error")
  • reset_log_level() -> bool: Resets log level to "trace" (maximum verbosity)

Dependencies Updated

  • Updated tracing-subscriber to version 0.3.18 (provides reload functionality)
  • Added once_cell 1.19 for thread-safe lazy static initialization

Core Changes

  • Modified setup_shared_logger() to use reloadable filter with reload::Layer
  • Added global RELOAD_HANDLE static variable for handle management
  • Enhanced subscriber setup to use Registry with layered architecture

Test Coverage

Added comprehensive tests covering:

  • ✅ Basic log level changing functionality
  • ✅ Log level reset functionality
  • ✅ Invalid log level handling
  • ✅ Null pointer safety
  • ✅ Error conditions and edge cases

Usage Example

// C/C++ usage
bool success = set_log_level("info");  // Set to info level
success = reset_log_level();           // Reset to trace level

Technical Notes

The implementation avoids the issues mentioned in the original issue regarding generic types in statics by using a type-erased approach with Box<dyn> and once_cell::Lazy instead of raw lazy_static. This provides a clean, thread-safe solution that works with the current tracing ecosystem.

🤖 Generated with Claude Code

Fixes #12

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #12
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 13:19
- Add global reload handle using tracing_subscriber::reload::Handle
- Implement set_log_level() FFI function to change log level dynamically
- Implement reset_log_level() FFI function to reset log level to trace
- Use tracing_subscriber 0.3.18 with reload functionality
- Add once_cell dependency for global handle management
- Add comprehensive tests for log level functionality
- Update setup_shared_logger to use reloadable filter

This addresses issue #12 by providing a way to reset log levels
through FFI without requiring newer tracing versions or complex
holder objects. The implementation uses a global lazy static
handle as suggested in the issue description.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Add log level resetting for FFI Add log level resetting functionality for FFI Sep 11, 2025
@konard konard marked this pull request as ready for review September 11, 2025 10:28
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.

Add log level resetting for FFI

1 participant