Skip to content

Commit 3fc86e7

Browse files
committed
feat: update README
1 parent e2fd1c3 commit 3fc86e7

1 file changed

Lines changed: 36 additions & 28 deletions

File tree

README.md

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,43 @@ targets: [
4040

4141
## Usage
4242

43-
### Basic logging
43+
### Setup
4444

45-
```swift
46-
import Logging
45+
Create one `Logging` instance per target, passing your subsystem, then store or pass it where needed:
4746

48-
Logging.network.info("Request started: \(url, privacy: .public)")
49-
Logging.auth.debug("Login attempt: \(email, privacy: .private)")
50-
Logging.data.error("Save failed: \(error)")
51-
Logging.lifecycle.notice("App moved to background")
47+
```swift
48+
// AppDelegate, @main struct, or dependency container
49+
let log = Logging(subsystem: "com.mycompany.MyApp")
5250
```
5351

54-
### Configuring the subsystem
52+
For quick prototyping the default init uses `"com.inesb.swift-logging"` as the subsystem:
5553

56-
`Logging.subsystem` defaults to `Bundle.main.bundleIdentifier`, so no setup is needed for app targets. Set it explicitly for framework or package targets:
54+
```swift
55+
let log = Logging()
56+
```
57+
58+
### Basic logging
5759

5860
```swift
59-
// Before any log call — AppDelegate or @main struct
60-
Logging.subsystem = "com.mycompany.MyFramework"
61+
import Logging
62+
63+
let log = Logging(subsystem: "com.mycompany.MyApp")
64+
65+
log.network.info("Request started: \(url, privacy: .public)")
66+
log.auth.debug("Login attempt: \(email, privacy: .private)")
67+
log.data.error("Save failed: \(error)")
68+
log.lifecycle.notice("App moved to background")
6169
```
6270

6371
### Privacy annotations
6472

6573
OSLog redacts interpolated values in release builds by default. Annotate values explicitly to control what is visible in production logs:
6674

6775
```swift
68-
Logging.auth.info("User: \(name, privacy: .private)") // redacted in release
69-
Logging.network.info("Status: \(code, privacy: .public)") // always visible
70-
Logging.auth.debug("Token: \(token, privacy: .sensitive)") // always redacted
71-
Logging.auth.info("ID: \(id, privacy: .private(mask: .hash))") // hashed for correlation
76+
log.auth.info("User: \(name, privacy: .private)") // redacted in release
77+
log.network.info("Status: \(code, privacy: .public)") // always visible
78+
log.auth.debug("Token: \(token, privacy: .sensitive)") // always redacted
79+
log.auth.info("ID: \(id, privacy: .private(mask: .hash))") // hashed for correlation
7280
```
7381

7482
## Log levels
@@ -84,19 +92,19 @@ Logging.auth.info("ID: \(id, privacy: .private(mask: .hash))") // hashed for co
8492

8593
## Categories
8694

87-
| Property | Intended use |
88-
|------------------------|-------------------------------------------|
89-
| `Logging.general` | Events that don't fit another category |
90-
| `Logging.network` | Requests, responses, connectivity |
91-
| `Logging.api` | Endpoint calls, serialisation |
92-
| `Logging.auth` | Login, logout, session management |
93-
| `Logging.user` | Profile, preferences, account events |
94-
| `Logging.data` | Persistence, migrations |
95-
| `Logging.cache` | In-memory and on-disk cache operations |
96-
| `Logging.ui` | View rendering, user interactions |
97-
| `Logging.navigation` | Push/pop, sheets, deep links |
98-
| `Logging.performance` | Measurements, profiling markers |
99-
| `Logging.lifecycle` | App and scene lifecycle events |
95+
| Property | Intended use |
96+
|-------------------|-------------------------------------------|
97+
| `.general` | Events that don't fit another category |
98+
| `.network` | Requests, responses, connectivity |
99+
| `.api` | Endpoint calls, serialisation |
100+
| `.auth` | Login, logout, session management |
101+
| `.user` | Profile, preferences, account events |
102+
| `.data` | Persistence, migrations |
103+
| `.cache` | In-memory and on-disk cache operations |
104+
| `.ui` | View rendering, user interactions |
105+
| `.navigation` | Push/pop, sheets, deep links |
106+
| `.performance` | Measurements, profiling markers |
107+
| `.lifecycle` | App and scene lifecycle events |
100108

101109
## Viewing logs
102110

0 commit comments

Comments
 (0)