Logging setup

From gustavscirulis/snapgrid · View interactive version

Logging setup is an AI agent skill from the GitHub repository gustavscirulis/snapgrid. 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.

How to use this skill

Skill file

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:

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:

Modes of Operation

Mode 1: Audit

Find all print() statements and report:

Grep: print\s*\(

Report format:

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?
  1. Include migration helpers?

Generation Process

Step 1: Create AppLogger.swift

Read template from templates/AppLogger.swift and customize:

Step 2: Determine File Location

Check project structure:

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

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

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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.