Logging Setup Generator
Replace print() statements with Apple's structured logging system (os.log/Logger) for better debugging, privacy controls, and Console.app integration.
When This Skill Activates
Use this skill when the user:
- Asks to "add logging" or "set up logging"
- Wants to "replace print statements"
- Mentions "os.log", "Logger", or "structured logging"
- Asks about "debug logging" or "production logging"
- Wants to audit print() usage in their codebase
Why Logger Over print()
| print() |
Logger |
| Always executes |
Debug logs compiled out in Release |
| No filtering |
Filter by subsystem/category in Console.app |
| No privacy |
.private, .public, .sensitive annotations |
| String interpolation always runs |
Deferred evaluation (performance) |
| Not in Console.app |
Full system integration |
Pre-Generation Checks
1. Project Context Detection
2. Conflict Detection
Search for existing logging:
Glob: **/*Logger*.swift
Grep: "import OSLog" or "os_log"
If found, ask user:
- Extend existing logging?
- Replace with new implementation?
- Create separate logger?
Modes of Operation
Mode 1: Audit
Find all print() statements and report:
Grep: print\s*\(
Report format:
- File:line - print statement
- Severity: Info/Warning/Error (based on context)
- Suggested Logger level
Mode 2: Generate
Create logging infrastructure from scratch.
Mode 3: Migrate
Convert existing print() to Logger with suggestions.
Configuration Questions
Ask user via AskUserQuestion:
Categories needed?
- Network, Auth, UI, Data (defaults)
- Custom categories?
Include migration helpers?
- Extension on String for quick migration
- Temporary print-to-log bridge
Generation Process
Step 1: Create AppLogger.swift
Read template from templates/AppLogger.swift and customize:
- Set subsystem from Bundle.main.bundleIdentifier
- Add user-specified categories
- Include usage examples in comments
Step 2: Determine File Location
Check project structure:
- If
Sources/ exists → Sources/Logging/AppLogger.swift
- If
App/ exists → App/Logging/AppLogger.swift
- Otherwise →
Logging/AppLogger.swift
Step 3: Provide Migration Guidance
Show examples of converting common print patterns:
// Before
print("User logged in: \(email)")
// After
AppLogger.auth.info("User logged in: \(email, privacy: .private)")
Output Format
After generation, provide:
Files Created
[Path]/Logging/AppLogger.swift
Integration Steps
- Import in files:
import OSLog (not needed if using AppLogger)
- Replace print() calls with AppLogger.[category].level
- Add privacy annotations for sensitive data
Privacy Annotations Guide
.public - Safe to log (IDs, counts, non-sensitive)
.private - Redacted in release (emails, names)
.sensitive - Always redacted (passwords, tokens)
Console.app Usage
- Open Console.app
- Filter by subsystem:
com.yourapp
- Filter by category:
Network, Auth, etc.
Testing Instructions
- Add a test log:
AppLogger.general.debug("Test log")
- Run app, check Xcode console
- Open Console.app, filter by your app's subsystem
References
- logger-patterns.md - Best practices and privacy levels
- migration-guide.md - Converting print() to Logger
- templates/AppLogger.swift - Template file
1---
2name: logging-setup
3description: Generates structured logging infrastructure using os.log/Logger to replace print() statements. Use when user wants to add proper logging, replace print statements, or set up app logging.
4allowed-tools: [Read, Write, Edit, Glob, Grep, Bash, AskUserQuestion]
5last_verified: 2026-07-16
6review_by: 2027-06-22
7os_version: iOS 27 / macOS 27
8---
9
10# Logging Setup Generator
11
12Replace print() statements with Apple's structured logging system (os.log/Logger) for better debugging, privacy controls, and Console.app integration.
13
14## When This Skill Activates
15
16Use this skill when the user:
17- Asks to "add logging" or "set up logging"
18- Wants to "replace print statements"
19- Mentions "os.log", "Logger", or "structured logging"
20- Asks about "debug logging" or "production logging"
21- Wants to audit print() usage in their codebase
22
23## Why Logger Over print()
24
25| print() | Logger |
26|---------|--------|
27| Always executes | Debug logs compiled out in Release |
28| No filtering | Filter by subsystem/category in Console.app |
29| No privacy | .private, .public, .sensitive annotations |
30| String interpolation always runs | Deferred evaluation (performance) |
31| Not in Console.app | Full system integration |
32
33## Pre-Generation Checks
34
35### 1. Project Context Detection
36- [ ] Check deployment target (Logger requires iOS 14+ / macOS 11+)
37- [ ] Search for existing Logger/os.log usage
38- [ ] Identify source file locations (Sources/, App/, etc.)
39
40### 2. Conflict Detection
41Search for existing logging:
42```
43Glob: **/*Logger*.swift
44Grep: "import OSLog" or "os_log"
45```
46
47If found, ask user:
48- Extend existing logging?
49- Replace with new implementation?
50- Create separate logger?
51
52## Modes of Operation
53
54### Mode 1: Audit
55Find all print() statements and report:
56```
57Grep: print\s*\(
58```
59
60Report format:
61- File:line - print statement
62- Severity: Info/Warning/Error (based on context)
63- Suggested Logger level
64
65### Mode 2: Generate
66Create logging infrastructure from scratch.
67
68### Mode 3: Migrate
69Convert existing print() to Logger with suggestions.
70
71## Configuration Questions
72
73Ask user via AskUserQuestion:
74
751. **Categories needed?**
76 - Network, Auth, UI, Data (defaults)
77 - Custom categories?
78
792. **Include migration helpers?**
80 - Extension on String for quick migration
81 - Temporary print-to-log bridge
82
83## Generation Process
84
85### Step 1: Create AppLogger.swift
86
87Read template from `templates/AppLogger.swift` and customize:
88- Set subsystem from Bundle.main.bundleIdentifier
89- Add user-specified categories
90- Include usage examples in comments
91
92### Step 2: Determine File Location
93
94Check project structure:
95- If `Sources/` exists → `Sources/Logging/AppLogger.swift`
96- If `App/` exists → `App/Logging/AppLogger.swift`
97- Otherwise → `Logging/AppLogger.swift`
98
99### Step 3: Provide Migration Guidance
100
101Show examples of converting common print patterns:
102```swift
103// Before
104print("User logged in: \(email)")
105
106// After
107AppLogger.auth.info("User logged in: \(email, privacy: .private)")
108```
109
110## Output Format
111
112After generation, provide:
113
114### Files Created
115- `[Path]/Logging/AppLogger.swift`
116
117### Integration Steps
1181. Import in files: `import OSLog` (not needed if using AppLogger)
1192. Replace print() calls with AppLogger.[category].[level]()
1203. Add privacy annotations for sensitive data
121
122### Privacy Annotations Guide
123- `.public` - Safe to log (IDs, counts, non-sensitive)
124- `.private` - Redacted in release (emails, names)
125- `.sensitive` - Always redacted (passwords, tokens)
126
127### Console.app Usage
1281. Open Console.app
1292. Filter by subsystem: `com.yourapp`
1303. Filter by category: `Network`, `Auth`, etc.
131
132### Testing Instructions
1331. Add a test log: `AppLogger.general.debug("Test log")`
1342. Run app, check Xcode console
1353. Open Console.app, filter by your app's subsystem
136
137## References
138
139- **logger-patterns.md** - Best practices and privacy levels
140- **migration-guide.md** - Converting print() to Logger
141- **templates/AppLogger.swift** - Template file