Skip to content

Conversation

@ssestak
Copy link

@ssestak ssestak commented Nov 3, 2025

This pull request introduces a comprehensive logging and analytics system with a strong focus on privacy. It enables automatic tracking of network activity, including requests, responses, and errors, with configurable data masking to protect sensitive information. The implementation leverages native OSLog for logging and provides a flexible protocol for analytics integration.

Key Features

  • Automatic Logging: Integrates with OSLog to automatically log network activity with configurable privacy levels (.none, .auto, .private, .sensitive).
  • Privacy-Aware Analytics: Introduces AnalyticsProtocol for tracking network events, featuring robust data masking for URLs, headers, and bodies to ensure user privacy.
  • Shared EntryType Enum: A new EntryType enum provides a consistent, type-safe data structure for both logging and analytics.
  • Configuration: LoggerConfiguration and AnalyticsConfiguration allow for detailed control over logging behavior and analytics data masking.
  • Seamless Integration: Logging and analytics are automatically triggered within the URLServer task lifecycle.
  • Unit Tests: Adds AnalyticsTests, LoggingTests, and URLServerLoggingTests to validate the new functionality.
  • Documentation: Updates README.md and DocC to cover the new features.

Logging vs. Analytics

Feature Logging (LogEntry) Analytics (AnalyticEntry)
Purpose Debugging and development monitoring. Business intelligence and usage tracking.
Backend Native OSLog. Custom AnalyticsProtocol implementation.
Privacy Control LogPrivacy enum (.none, .auto, .private, .sensitive). AnalyticsPrivacy enum (.none, .private, .sensitive).
Configuration LoggerConfiguration (subsystem, category, privacy). AnalyticsConfiguration (privacy, unmasked keys).
Output Formatted text messages in the console. Structured data passed to the analytics service.

Šimon Šesták added 18 commits October 27, 2025 11:29
Adds a new network logging module using OSLog, providing configurable privacy levels, custom data decoding, and analytics callbacks for network requests and responses.
Introduces privacy masking for `LogEntry` objects sent to analytics callbacks, preventing sensitive data leakage. Centralizes log message building within `LogEntry` for improved code organization and maintainability.
This refactoring separates network logging from analytics tracking, introducing a dedicated analytics system with its own privacy configuration and data handling, and updating `URLServer` to support distinct logger and analytics components.
Removes the unused NoOpAnalytics implementation and its corresponding test.
Introduces a new analytics module for network requests and responses, featuring configurable privacy levels to mask sensitive data in URLs, headers, and body. Includes comprehensive documentation and examples.
Refactors AnalyticEntry and LogEntry to use an associated value EntryType enum,
ensuring relevant data (method, url, statusCode, error) is explicitly
tied to each entry type, enhancing type safety and data consistency.
Removes external Markdown files (ANALYTICS.md, LOGGING.md) and integrates their content as inline DocC documentation within the source code for improved discoverability and consistency.
Moved analytics-related tests from `LoggingTests.swift` to a new `AnalyticsTests.swift` file for better organization and separation of concerns.
Introduces structured logging with aligned fields, sorted headers, and timestamps for improved clarity and consistency across request, response, and error entries.
…nd category

Moved subsystem and category parameters from LoggerConfiguration to DefaultLogger's initializer for better flexibility and clearer separation of concerns.
Moves os.log calls from DefaultLogger to URLServer+Task and updates LoggerProtocol to provide the underlying os.Logger and its configuration. This simplifies the logging protocol and centralizes the os.log integration.
Removed LoggerProtocol and DefaultLogger by embedding the os.Logger instance directly within LoggerConfiguration. This simplifies the logging setup and reduces abstraction.
…ternal

Encapsulate internal logging details by restricting access to LogEntry struct and LoggerConfiguration properties.
Removed redundant usage examples and requirements from various documentation comments. Updated the list of key logging components in README and main documentation.
…rs and recursive body masking

Refactors the analytics privacy configuration to provide more granular control over data masking by specifying unmasked parameters instead of sensitive ones. Introduces recursive masking for JSON body content and removes the 'auto' privacy level for clearer definitions.
@ssestak ssestak requested a review from jmarek41 November 3, 2025 09:54
@ssestak ssestak closed this Nov 3, 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.

2 participants