Skip to content

Conversation

@sanchitmehta94
Copy link
Contributor

@sanchitmehta94 sanchitmehta94 commented Dec 3, 2025

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

📋 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.

  1. Debug amd Info levels logs are not persisted and for other log levels , i have kept all logs redacted when debugger is not connected in system logs. you can see them in console.app when debugger is connected not otherwise
Screenshot 2025-12-07 at 5 46 55 PM
  1. have added handling to redact the sensitive info the API response being logged to Xcode console where earlier it was printing everything eg. refresh token, access token and Identity Token , now we will redact these as shown below Also made sure json is printted in pretty-printed format.
Screenshot 2025-12-07 at 6 28 11 PM
  1. Also I have offloaded all network tracing computation to background thread by using a serial queue keeping main thread free (avoid freeze)

📎 References

🎯 Testing

@sanchitmehta94 sanchitmehta94 requested a review from a team as a code owner December 3, 2025 19:29
@sanchitmehta94 sanchitmehta94 force-pushed the feature/improveSDKLoggingDX branch from 411ab96 to 816228e Compare December 3, 2025 20:34
@sanchitmehta94 sanchitmehta94 changed the title feat: add OSLog support for better SDK debugging and troubleshooting chore: Add OSLog support for better SDK debugging and developer experience Dec 4, 2025
@sanchitmehta94 sanchitmehta94 marked this pull request as draft December 4, 2025 04:32
@sanchitmehta94 sanchitmehta94 self-assigned this Dec 4, 2025
@sanchitmehta94 sanchitmehta94 force-pushed the feature/improveSDKLoggingDX branch from 816228e to 54d8283 Compare December 4, 2025 05:08
@sanchitmehta94 sanchitmehta94 marked this pull request as ready for review December 4, 2025 10:37
let messageString = message()

switch (level, isPublic) {
case (.debug, true):
Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor Author

@sanchitmehta94 sanchitmehta94 Dec 5, 2025

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)") 

Copy link
Contributor

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

Copy link
Contributor Author

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 .

@sanchitmehta94 sanchitmehta94 force-pushed the feature/improveSDKLoggingDX branch from 954c893 to 8df6cc7 Compare December 4, 2025 10:46
@sanchitmehta94 sanchitmehta94 removed their assignment Dec 5, 2025
@sanchitmehta94 sanchitmehta94 force-pushed the feature/improveSDKLoggingDX branch from b77f307 to ca6339c Compare December 5, 2025 07:15
@NandanPrabhu
Copy link
Contributor

@claude

@sanchitmehta94 sanchitmehta94 force-pushed the feature/improveSDKLoggingDX branch from ca6339c to 0fe4de7 Compare December 5, 2025 09:08
@sanchitmehta94 sanchitmehta94 force-pushed the feature/improveSDKLoggingDX branch from 0fe4de7 to 4db9118 Compare December 5, 2025 09:14

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)")
Copy link
Contributor Author

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.

Copy link

Copilot AI left a 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 Auth0Log unified logging system with OSLog backend supporting debug, info, warning, error, and fault levels
  • Replaced all debug print() calls with Auth0Log calls 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.

@sanchitmehta94 sanchitmehta94 changed the title chore: Add OSLog support for better SDK debugging and developer experience chore: Add OSLog support for better SDK debugging/DX and redact sensitive tokens logging. Dec 7, 2025
}
print(error)
} catch {
print(error)
Copy link
Contributor Author

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

@sanchitmehta94 sanchitmehta94 merged commit aa4dcd8 into master Dec 8, 2025
12 of 13 checks passed
@sanchitmehta94 sanchitmehta94 deleted the feature/improveSDKLoggingDX branch December 8, 2025 07:16

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)
Copy link
Contributor Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:medium Medium review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants