Updated logging to use prepared statements, improving security and performance. Refactored Redis-related functions for flexibility, added timing for sync operation, and ensured proper cache cleanup after log synchronization. Simplified `clear_keys` and enhanced code readability throughout.