Logging for Swift (iOS/macOS): Best Libraries and Solutions

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Logging for Swift (iOS/macOS): Best Solutions



Logging is one of the key tools for iOS and macOS application developers. It helps track code execution, find bugs, analyze user behavior, and diagnose problems in production. The Swift ecosystem offers many libraries and approaches for organizing logging. In this article, we will review the best ones, their advantages, and usage examples.



Why is logging needed in Swift?

High-quality logging allows you to:

  • Track execution flow and variable state
  • Record errors and exceptions with context
  • Analyze performance and bottlenecks
  • Collect data for debugging in production (via remote services)
  • Simplify team development and code review


Built-in Solution: OSLog (os_log)

Starting with iOS 10 / macOS 10.12, Apple provides a powerful framework os_log. It is integrated into the system, supports categories, severity levels, and dynamic filtering in the Xcode console and the Console app.

import os.log

let logger = OSLog(subsystem: "com.yourapp.networking", category: "APIClient")os_log("Request to server: %{public}@", log: logger, type: .info, urlString)

// Levels: .debug, .info, .default, .error, .faultos_log("Authorization error: %{public}@", log: logger, type: .error, errorMessage)

Pros: zero dependencies, high performance, Apple support. Cons: limited output customization, complexity of integration with cloud services.



Best Third-Party Library: CocoaLumberjack

CocoaLumberjack is the de facto standard for logging in Swift and Objective-C. It is several times faster than NSLog, supports asynchronous writing, file rotation, multiple loggers simultaneously, and formatting.

import CocoaLumberjack

// SetupDDLog.add(DDOSLogger.sharedInstance) // Consolelet fileLogger = DDFileLogger()fileLogger.rollingFrequency = 60 * 60 * 24 // 24 hoursDDLog.add(fileLogger)

// UsageDDLogDebug("Debug: \\(someValue)")DDLogInfo("Info: user logged in")DDLogWarn("Warning: low battery")DDLogError("Error: failed to load data")

The library is actively maintained, has a huge community, and is easily customizable for any needs.



SwiftyBeaver: Beautiful Output and Cloud Analytics

SwiftyBeaver is a popular solution with colored console output, JSON format support, and a built-in cloud service for real-time log collection.

import SwiftyBeaver

let log = SwiftyBeaver.self

// Add console destinationlet console = ConsoleDestination()log.addDestination(console)

// Optional: cloud servicelet cloud = SBPlatformDestination(appID: "yourAppID", appSecret: "secret", encryptionKey: "key")log.addDestination(cloud)

log.verbose("App launch")log.debug("Parameters: \\(params)")log.info("User pressed button")log.warning("Connection timeout")log.error("Critical error: \\(error)")

SwiftyBeaver is great for small and medium projects where visual comfort during development is important.



XCGLogger: Flexibility and Simplicity

XCGLogger is a lightweight library with rich formatting capabilities, filtering by tags and levels. It supports output to file, console, and custom destinations.

import XCGLogger

let log = XCGLogger.defaultlog.setup(level: .debug, showLogIdentifier: true, showFunctionName: true, showThreadName: true, showLevel: true, showFileNames: true, showLineNumbers: true)

log.debug("Debug")log.info("Info")log.error("Error")

Simple setup and a clear API make

Recommendations