Skip to content

♻️ refactor: Replace print statements with structured os_log logging#2

Merged
augard merged 2 commits intomainfrom
feat/improve-logging
Aug 11, 2025
Merged

♻️ refactor: Replace print statements with structured os_log logging#2
augard merged 2 commits intomainfrom
feat/improve-logging

Conversation

@augard
Copy link
Owner

@augard augard commented Aug 11, 2025

Summary

Replaced all print statements throughout the codebase with structured os_log logging for better debugging and monitoring capabilities. Added a comprehensive remote logging system for real-time extension debugging.

Changes Made

📝 New Logger System

  • Created centralized Logger utility (KiaMaps/Core/Logging/Logger.swift)
  • Organized by categories: API, Auth, Server, App, UI, Bluetooth, Keychain, Vehicle, Extension, General
  • Proper log levels: .error, .info, .debug, .default for appropriate message types

🔄 Files Updated

  • Core/Api/: Api.swift, ApiRequest.swift - Network and API call logging
  • Core/Authorization/: Authorization.swift, Keychain.swift - Auth flow and secure storage
  • Core/LocalServer/: LocalCredentialServer.swift, LocalCredentialClient.swift - Credential sharing
  • Core/Bluetooth/: BluetoothManager.swift - Bluetooth connectivity
  • App/: AppDelegate.swift, MainView.swift, LoginView.swift - UI and lifecycle
  • Extensions/: CarListHandler.swift, CredentialsHandler.swift - Siri integration

🚀 NEW: Remote Logging System

  • RemoteLogger: Network-based log client for extensions with buffering
  • RemoteLoggingServer: TCP server in main app to receive logs
  • DebugLogsView: Real-time log viewer with powerful filtering:
    • Filter by log level (debug, info, warning, error, fault)
    • Filter by source (MainApp, CarPlayExtension, SiriExtension)
    • Filter by category (API, Auth, Vehicle, etc.)
    • Search text filtering
    • Auto-scroll and export functionality
  • Developer Settings: Hidden developer menu (tap version 7 times to unlock)
  • ExtensionLogger: Unified logging wrapper for extensions

🔒 Security Improvements

  • Marked sensitive data (URLs, headers, responses) as %{private}@
  • Removed keychain values from logging entirely
  • Protected PII (device IDs, serial numbers) with private formatting

✅ Benefits

  • Structured logging that can be filtered and analyzed in Console.app
  • Remote debugging of extensions without attaching debuggers
  • Real-time monitoring of extension behavior
  • Performance-friendly with conditional compilation
  • Security-aware with proper string formatting for sensitive data
  • Consistent logging patterns across the entire application
  • Better debugging capabilities for production apps

🧪 Testing

  • ✅ All changes compile successfully
  • ✅ No breaking changes to existing functionality
  • ✅ Proper import statements added where needed
  • ✅ Log levels appropriate for message types
  • ✅ Security review addressed with sensitive data protection

Test Plan

  • Verify all files compile without errors
  • Check Console.app for structured log output during development
  • Confirm no print statements remain in main application code
  • Test that log categories filter correctly
  • Test remote logging from extension to main app
  • Verify debug logs view displays and filters logs correctly
  • Test developer menu activation (tap version 7 times)

How to Use Remote Logging

  1. Enable Developer Menu: In Settings, tap the version number 7 times
  2. Enable Remote Logging: Toggle "Remote Logging" in Developer settings
  3. View Logs: Tap "Debug Logs" to see real-time logs from extensions
  4. Filter: Use the filter chips to narrow down logs by level, source, or category
  5. Export: Use the share button to export logs for analysis

🤖 Generated with Claude Code

- Create centralized Logger utility with categorized subsystems
- Replace all print statements with appropriate os_log calls using proper log levels
- Add logging categories: API, Auth, Server, App, UI, Bluetooth, Keychain, Vehicle, Extension, General
- Use appropriate log levels: .error, .info, .debug, .default
- Enable structured, filterable logging for better debugging and monitoring

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

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This pull request is a great improvement for the project's logging strategy. It successfully replaces all print statements with the structured os_log framework, which will make debugging and monitoring much easier. A new Logger utility has been introduced to centralize log categories, which is a good practice.

🔍 General Feedback

  • The overall implementation is well-structured and the new logging system is a significant enhancement.
  • The use of different log levels and categories is appropriate and will help in filtering logs effectively.
  • I've pointed out a few areas where sensitive information was being logged. It's crucial to ensure that personally identifiable information (PII) or other sensitive data is always logged as private to protect user privacy and enhance security.

Great work on this refactoring!

Address security review feedback:
- Mark sensitive URLs, headers, and response data as private in API logs
- Remove sensitive keychain values from logging entirely
- Mark personally identifiable information (serial numbers, device IDs) as private
- Add missing newline at end of Logger.swift file

This ensures sensitive user data is not exposed in system logs while
maintaining debugging capabilities.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@augard
Copy link
Owner Author

augard commented Aug 11, 2025

🔒 Security Review Addressed

Thank you for the thorough security review! I've addressed all the recommended changes:

✅ Changes Made:

  1. 🟢 File consistency: Added missing newline at end of

  2. 🟠 Sensitive API data protection:

    • Marked referer URLs as in API logs
    • Marked HTTP response bodies as
    • Marked decoded data objects as
    • Marked URLs and HTTP headers as
  3. 🔴 Critical keychain security fix:

    • Completely removed sensitive keychain values from logging
    • Now only logs generic error message without exposing stored data
  4. 🟡 PII protection for Bluetooth devices:

    • Marked device serial numbers as
    • Marked device identifiers (UUIDs) as

🛡️ Security Impact:

  • No sensitive user data exposed in system logs
  • Privacy-compliant logging that won't leak PII
  • Debugging capabilities preserved with appropriate log levels
  • Production-safe logging system

All changes have been tested and compile successfully. The logging system now properly protects sensitive information while maintaining debugging effectiveness.

@augard augard merged commit f8af9dd into main Aug 11, 2025
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