Debugging Logs

How to enable and interpret debugging logs for TheCompanyApp.

Enable Logging

Core Data CloudKit Debugging

Xcode Scheme Arguments:

  1. Product → Scheme → Edit Scheme...

  2. Run → Arguments tab

  3. Arguments Passed On Launch → Click "+"

  4. Add each argument:

-com.apple.CoreData.CloudKitDebug 3
-com.apple.CoreData.Logging.oslog 1
-com.apple.CoreData.ConcurrencyDebug 1

Levels:

  • 1 = Errors only

  • 2 = Warnings + Errors

  • 3 = Info + Warnings + Errors (verbose)

Result: CloudKit sync logs appear in Xcode console.

CloudKit Container Logging

Additional Argument:

Logs: Container setup, account status, zone creation.

Network Logging

Environment Variable:

  1. Edit Scheme → Run → Arguments tab

  2. Environment Variables → Click "+"

  3. Add:

    • Name: CFNETWORK_DIAGNOSTICS

    • Value: 3

Result: HTTP/HTTPS requests logged.

Reading Logs in Xcode

Run App from Xcode

  1. Build and run (⌘R)

  2. Perform action (e.g., save company, accept share)

  3. View logs in Debug Console (bottom panel)

Filter Logs

Search Bar (bottom right of console):

  • Filter by "CloudKit": CloudKit

  • Filter by errors: error

  • Filter by specific entity: Companies

Example Log:

Common Log Patterns

Successful Sync

Export (Upload):

Import (Download):

Sync Errors

Network Unavailable:

Not Authenticated:

Quota Exceeded:

Share Creation:

Share Acceptance:

Enlistment:

Console.app (macOS)

Use Case: View logs from physical device or Simulator.

Setup

  1. Connect device to Mac (or run Simulator)

  2. Open Console.app (Applications → Utilities)

  3. Select device in sidebar

  4. Start monitoring

Filter Console Logs

Search Field:

Additional Filters:

Result: See all CloudKit-related logs for TheCompanyApp.

Export Logs

  1. Console.app → Edit → Find → Filter Logs

  2. Select filtered logs

  3. File → Export...

  4. Save as .txt or .log file

CloudKit Dashboard

Web Interface: https://icloud.developer.apple.com/dashboardarrow-up-right

View Records

  1. Select "TheCompanyApp" container

  2. Choose Environment: Development or Production

  3. Click Data → Records

  4. Select zone (Private or Shared)

  5. Browse records by type: CD_Companies, CD_InventoryItem, etc.

Useful for:

  • Verify records uploaded

  • Check field values

  • Inspect CKShare records

Monitoring Logs

  1. Dashboard → Logs

  2. View real-time CloudKit operations

  3. Filter by operation type: Save, Fetch, QueryRecords

Example:

Telemetry

  1. Dashboard → Telemetry

  2. View:

    • Request count over time

    • Error rate

    • Database usage (MB)

Debugging Crashes

Enable Crash Reporting

TestFlight: Automatic (testers opt-in).

Xcode: Crashes logged in Xcode console immediately.

Symbolicate Crash Reports

Get Crash Report:

  • Xcode → Window → Devices and Simulators

  • Select device → View Device Logs

  • Select crash report

Symbolication:

  • Drag .crash file to Xcode window

  • Xcode auto-symbolicates if dSYM available

  • View stack trace with function names

Manual Symbolication:

Replace 0x100000000 (load address) and 0x10000abcd (crash address) from crash report.

Common Crash Patterns

CloudKit Timeout:

Fix: Increase timeout, check network.

Core Data Concurrency:

Fix: Ensure context.perform { } used for background operations.

Interpreting Sync Issues

Symptom: Data Not Syncing

Check Logs For:

  1. Export started → Export successful?

  2. If failed → Error code (CKErrorDomain)

  3. Network, authentication, quota errors?

Example Diagnosis:

→ Code 9 = Not authenticated → User not signed in to iCloud.

Symptom: Share Not Working

Check Logs For:

  1. Creating share for record → Share created?

  2. Share metadata fetched → Metadata valid?

  3. Share accepted → Acceptance succeeded?

  4. Enlisting records → All related data enlisted?

Example Diagnosis:

→ Enlistment failed → Check if related data has correct companyID.

Logging in Production

Disable Debug Logs: Remove Xcode scheme arguments for Release builds.

Implement Custom Logging:

Usage:

View in Console.app:

Performance Profiling

Instruments (Xcode):

  1. Product → Profile (⌘I)

  2. Select template: Core Data

  3. Record while performing actions

  4. Analyze:

    • Fetch times

    • Save times

    • Faulting behavior

Identify Slow Queries: Look for fetches > 100ms.

Optimize: Add indexes, reduce fetch batch size, use predicates.


Related: Troubleshooting, Share Testing Checklist, Common Issues

Last updated