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