-
Notifications
You must be signed in to change notification settings - Fork 254
chore: Add OSLog support for better SDK debugging/DX and redact sensitive tokens logging. #1030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
411ab96 to
816228e
Compare
816228e to
54d8283
Compare
Auth0/Auth0Log.swift
Outdated
| let messageString = message() | ||
|
|
||
| switch (level, isPublic) { | ||
| case (.debug, true): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work - OSLog needs compile-time constant
let privacy: OSLogPrivacy = isPublic ? .public : .private
so have to do this way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use an enum in the place of a boolean. OSLogPrivacy has multiple options. So acomodating all these options will be easy using an enum https://developer.apple.com/documentation/os/oslogprivacy#Getting-the-Privacy-Options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fair point Nandan
however, as i mentioned above OSLog API, the privacy parameter in OSLog interpolation (e.g., (value, privacy: .public)) requires a compile-time constant from the OSLogPrivacy enum. This is a fundamental limitation of OSLog's design for security reasons. .
This does NOT work:
let privacyLevel: OSLogPrivacy = .public
logger.debug("\(value, privacy: privacyLevel)")
This works:
logger.debug("\(value, privacy: .public)")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense. but lets plz refrain from using boolean here. a new enum imitating OSLogPrivacy with a different name should solve the purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve removed the isPublic check and kept all logs private. We don’t want to show any information when the debugger is not attached. Most of these logs are debug-only and are never persisted. Redaction only applies for string interpolation when a debugger is disconnected, and we want the full string to remain private if anything ever gets persisted. Therefore, I’m dropping support for any other visibility options for safe side we will see if we need this in future .
954c893 to
8df6cc7
Compare
b77f307 to
ca6339c
Compare
ca6339c to
0fe4de7
Compare
0fe4de7 to
4db9118
Compare
|
|
||
| guard let clientId = values["ClientId"] as? String, let domain = values["Domain"] as? String else { | ||
| print("Auth0.plist file at \(path) is missing 'ClientId' and/or 'Domain' entries!") | ||
| print("File currently has the following entries: \(values)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auth0Log.debug(.configuration, "File currently has the following entries: \(String(describing: values))")
I have deliberately marked this as a debug log, because if a developer unknowingly includes sensitive tokens in the plist, it won’t pose a risk — debug logs are not persisted to disk, whereas error logs are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR modernizes the Auth0 iOS SDK's debugging experience by migrating from print() statements to Apple's OSLog framework. The change introduces structured, categorized logging with privacy controls while maintaining backward compatibility through the existing .logging(enabled: true) API.
Key Changes
- Introduced
Auth0Logunified logging system with OSLog backend supporting debug, info, warning, error, and fault levels - Replaced all debug
print()calls withAuth0Logcalls using appropriate categories (NetworkTracing, Configuration) - Added comprehensive documentation for filtering logs in Xcode 15+ console
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| Auth0/Auth0Log.swift | New unified logging system with OSLog implementation, protocols, and convenience methods |
| Auth0Tests/LoggerSpec.swift | Comprehensive test suite for Auth0Log with mock service and test coverage for all log levels |
| Auth0/Logger.swift | Updated DefaultOutput to use Auth0Log instead of print() |
| Auth0/Request.swift | Replaced print() error statements with Auth0Log.debug() |
| Auth0/Auth0.swift | Replaced print() configuration error messages with Auth0Log.error() and Auth0Log.debug() |
| README.md | Added logging documentation section with filtering instructions and category descriptions |
| Auth0.xcodeproj/project.pbxproj | Added Auth0Log.swift to all build targets |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| print(error) | ||
| } catch { | ||
| print(error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed this . These got accidently added in this PR
|
|
||
| Auth0.swift uses Apple's Unified Logging (OSLog) to help you troubleshoot issues during development. Enable detailed HTTP logging to see network requests, responses, and errors. | ||
|
|
||
| ### Enable Logging (NetworK Tracing based logs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: fixing in next PR (Network Tracing based logs)
📋 Changes
Improve DX by using OSLog framework for debug loggin in Auth0 iOS SDK
https://auth0team.atlassian.net/browse/SDK-7255
https://oktawiki.atlassian.net/wiki/spaces/DXSDK/pages/2883787251/Next+major+of+Auth0.swift+Non-breaking+changes#5.-Use-OSLog-instead-of-print()-for-debug-logging
Why we should use OSLog?
The OSLog framework is Apple's modern, highly efficient, and structured logging system designed to replace older methods like print and NSLog. It significantly improves performance by having a low overhead, deferring work, and avoiding the blocking of the main thread. By using subsystems and categories, it enables developers to organize logs clearly for easy filtering in the Xcode Console app. Crucially, it provides essential privacy controls to redact sensitive data, supports various log levels (debug, error, fault) for better control over data collection, and integrates seamlessly with sysdiagnose reports for reliable debugging of production issues.
📎 References
🎯 Testing