Skip to content

Commit 3f71f20

Browse files
Update Logging Docs in Example.md file
1 parent 15ff6ae commit 3f71f20

File tree

2 files changed

+78
-8
lines changed

2 files changed

+78
-8
lines changed

EXAMPLES.md

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,7 +2965,11 @@ Check the [API documentation](https://auth0.github.io/Auth0.swift/documentation/
29652965

29662966
## Logging
29672967

2968-
Auth0.swift can print HTTP requests and responses for debugging purposes. Enable it by calling the following method in either `WebAuth`, `Authentication` or `Users`:
2968+
Auth0.swift provides comprehensive logging capabilities for debugging HTTP requests and responses. The logging system is built on Apple's [Unified Logging](https://developer.apple.com/documentation/os/logging) (`OSLog`) for better performance and integration with system diagnostic tools.
2969+
2970+
### Enable Logging
2971+
2972+
Enable logging by calling the `logging(enabled:)` method on `WebAuth`, `Authentication`, or `Users`:
29692973

29702974
```swift
29712975
Auth0
@@ -2974,32 +2978,98 @@ Auth0
29742978
// ...
29752979
```
29762980

2981+
```swift
2982+
Auth0
2983+
.authentication()
2984+
.logging(enabled: true)
2985+
// ...
2986+
```
2987+
2988+
```swift
2989+
Auth0
2990+
.users(token: credentials.accessToken)
2991+
.logging(enabled: true)
2992+
// ...
2993+
```
2994+
29772995
> [!CAUTION]
2978-
> Set this flag only when **DEBUGGING** to avoid leaking user's credentials in the device log.
2996+
> Enable logging **only when debugging** to avoid performance impacts and potential security concerns in production builds.
2997+
2998+
### Automatic Token Redaction
29792999

2980-
With a successful authentication you should see something similar to the following:
3000+
**Security First**: Auth0.swift automatically redacts sensitive information from logs to protect user credentials. The following fields are redacted when logging HTTP responses:
3001+
3002+
- `access_token`
3003+
- `refresh_token`
3004+
- `id_token`
3005+
3006+
Redacted tokens appear as `"redacted"` in the logs, ensuring sensitive data never appears in plain text.
3007+
3008+
### Logging Output
3009+
3010+
With logging enabled, you'll see detailed HTTP request and response information. Here's an example of what a successful authentication flow looks like:
29813011

29823012
```text
29833013
ASWebAuthenticationSession: https://example.us.auth0.com/authorize?.....
29843014
Callback URL: com.example.MyApp://example.us.auth0.com/ios/com.example.MyApp/callback?...
3015+
29853016
POST https://example.us.auth0.com/oauth/token HTTP/1.1
29863017
Content-Type: application/json
29873018
Auth0-Client: eyJ2ZXJzaW9uI...
29883019
2989-
{"code":"...","client_id":"...","grant_type":"authorization_code","redirect_uri":"com.example.MyApp:\/\/example.us.auth0.com\/ios\/com.example.MyApp\/callback","code_verifier":"..."}
3020+
{
3021+
"code": "...",
3022+
"client_id": "...",
3023+
"grant_type": "authorization_code",
3024+
"redirect_uri": "com.example.MyApp://example.us.auth0.com/ios/com.example.MyApp/callback",
3025+
"code_verifier": "..."
3026+
}
29903027
29913028
HTTP/1.1 200
29923029
Pragma: no-cache
29933030
Content-Type: application/json
29943031
Strict-Transport-Security: max-age=3600
2995-
Date: Wed, 27 Apr 2022 19:04:39 GMT
2996-
Content-Length: 57
3032+
Date: Wed, 08 Dec 2025 10:30:00 GMT
3033+
Content-Length: 1024
29973034
Cache-Control: no-cache
29983035
Connection: keep-alive
29993036
3000-
{"access_token":"...","token_type":"Bearer"}
3037+
{
3038+
"access_token": "redacted",
3039+
"refresh_token": "redacted",
3040+
"id_token": "redacted",
3041+
"token_type": "Bearer",
3042+
"expires_in": 86400
3043+
}
30013044
```
30023045

3046+
### Viewing Logs
3047+
3048+
Auth0.swift logs are written to the **Unified Logging System** with the following identifiers:
3049+
3050+
- **Subsystem**: `com.auth0.Auth0`
3051+
- **Categories**: `NetworkTracing`, `Configuration`
3052+
3053+
#### Xcode Console (Recommended)
3054+
3055+
Logs appear automatically in the Xcode debug console during development on all platforms.
3056+
3057+
**Filtering in Xcode 15+:**
3058+
3059+
Use these filter expressions directly in the console search bar:
3060+
3061+
| Filter | Description |
3062+
|--------|-------------|
3063+
| `subsystem:com.auth0.Auth0` | Show all Auth0 SDK logs |
3064+
| `category:NetworkTracing` | Show only network requests/responses |
3065+
| `category:Configuration` | Show only configuration errors |
3066+
| `subsystem:com.auth0.Auth0 category:NetworkTracing` | Combine filters for specific logs |
3067+
3068+
#### Log Categories
3069+
3070+
- **NetworkTracing** - HTTP requests and responses (enabled via `logging(enabled: true)`)
3071+
- **Configuration** - SDK setup and configuration issues (always logged)
3072+
30033073
> [!TIP]
30043074
> When troubleshooting, you can also check the logs in the [Auth0 Dashboard](https://manage.auth0.com/#/logs) for more information.
30053075

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ Check the [FAQ](FAQ.md) for more information about the alert box that pops up **
347347

348348
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.
349349

350-
### Enable Logging (NetworK Tracing based logs)
350+
### Enable Logging (Network Tracing based logs)
351351

352352
To enable detailed HTTP request and response tracing during development:
353353

0 commit comments

Comments
 (0)