logging-setup

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.

149 stars

Best use case

logging-setup is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

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.

Teams using logging-setup should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/logging-setup/SKILL.md --create-dirs "https://raw.githubusercontent.com/rshankras/claude-code-apple-skills/main/skills/generators/logging-setup/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/logging-setup/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How logging-setup Compares

Feature / Agentlogging-setupStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

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.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 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
- [ ] Check deployment target (Logger requires iOS 14+ / macOS 11+)
- [ ] Search for existing Logger/os.log usage
- [ ] Identify source file locations (Sources/, App/, etc.)

### 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:

1. **Categories needed?**
   - Network, Auth, UI, Data (defaults)
   - Custom categories?

2. **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:
```swift
// 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
1. Import in files: `import OSLog` (not needed if using AppLogger)
2. Replace print() calls with AppLogger.[category].[level]()
3. 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
1. Open Console.app
2. Filter by subsystem: `com.yourapp`
3. Filter by category: `Network`, `Auth`, etc.

### Testing Instructions
1. Add a test log: `AppLogger.general.debug("Test log")`
2. Run app, check Xcode console
3. 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

Related Skills

snapshot-test-setup

149
from rshankras/claude-code-apple-skills

Set up SwiftUI visual regression testing with swift-snapshot-testing. Generates snapshot test boilerplate and CI configuration. Use for UI regression prevention.

persistence-setup

149
from rshankras/claude-code-apple-skills

Generates SwiftData or CoreData persistence layer with optional iCloud sync. Use when user wants to add local storage, data persistence, or cloud sync.

offer-codes-setup

149
from rshankras/claude-code-apple-skills

Generates offer code distribution strategies and configuration guides for subscription and IAP promotions — including partner campaigns, influencer programs, and email re-engagement. Use when setting up offer codes for distribution.

localization-setup

149
from rshankras/claude-code-apple-skills

Generate internationalization (i18n) infrastructure for multi-language support in iOS/macOS apps. Use when localizing for multiple languages, adopting String Catalogs (xcstrings), or supporting RTL languages.

ci-cd-setup

149
from rshankras/claude-code-apple-skills

Generate CI/CD configuration for automated builds, tests, and distribution of iOS/macOS apps. Use when setting up GitHub Actions, Xcode Cloud, or fastlane for continuous integration, TestFlight, or App Store deployment.

analytics-setup

149
from rshankras/claude-code-apple-skills

Generates protocol-based analytics infrastructure with swappable providers (TelemetryDeck, Firebase, Mixpanel). Use when user wants to add analytics, track events, or set up telemetry.

watchOS

149
from rshankras/claude-code-apple-skills

watchOS development guidance including SwiftUI for Watch, Watch Connectivity, complications, and watch-specific UI patterns. Use for watchOS code review, best practices, or Watch app development.

visionos-widgets

149
from rshankras/claude-code-apple-skills

visionOS widget patterns including mounting styles, glass/paper textures, proximity-aware layouts, and spatial widget families. Use when creating or adapting widgets for visionOS.

test-data-factory

149
from rshankras/claude-code-apple-skills

Generate test fixture factories for your models. Builder pattern and static factories for zero-boilerplate test data. Use when tests need sample data setup.

test-contract

149
from rshankras/claude-code-apple-skills

Generate protocol/interface test suites that any implementation must pass. Define the contract once, test every implementation. Use when designing protocols or swapping implementations.

tdd-refactor-guard

149
from rshankras/claude-code-apple-skills

Pre-refactor safety checklist. Verifies test coverage exists before AI modifies existing code. Use before asking AI to refactor anything.

tdd-feature

149
from rshankras/claude-code-apple-skills

Red-green-refactor scaffold for building new features with TDD. Write failing tests first, then implement to pass. Use when building new features test-first.