Logly
Logly is a Swift package for structured logging in iOS and macOS apps. You create one log category per functional area of your app and write messages at five levels. Logly prints them formatted to the console, optionally writes them to a file with automatic rotation, and passes them on to your own destinations (sinks), for example Sentry.
What Logly does
The following table lists the features of Logly with a short explanation and the page that describes them:
| Feature | In short | Page |
|---|---|---|
| Five log levels | debug, info, warning, error, fault with a configurable minimum level | Logging |
| Categories | One logger per area, e.g. Network or Database | Logging |
Synchronous and async API | Every log method and every setting exists in both variants | Logging, Configuration |
| Central configuration | One thread-safe object, LoggerConfiguration.shared | Configuration |
| Output format | Format string with placeholders, fixed column widths, ANSI colors | Output format |
| Log file | Writing to a file, rotation by size and age, cleanup of old files | Log files |
| Background processing | Formatting and writing on a dedicated serial queue | Configuration |
| Crash handling | Logs uncaught exceptions and reports fatal signals | Crash handling |
| Custom destinations (sinks) | Pass structured events, including the Error, to your own code | Custom sinks |
| Sentry integration | Optional LoglySentry product | Sentry |
Structure of Logly
The Logly package provides two libraries:
Logly: the core, without external dependencies.LoglySentry: an optional Sentry backend. It is only built when you enable theSentrypackage trait. Without the trait the module is empty andsentry-cocoais not fetched.
In Logly, a log message goes through these steps:
- You call e.g.
logger.info("…"). - Logly reads a snapshot of the configuration and compares the message level with
currentLogLevel. If it is lower, the call ends here. - If
asynchronousLoggingis on, the following steps run on a serial background queue, otherwise directly on the calling thread. - The message is formatted according to
logFormatand printed withprint, colored if enabled. - If
logToFileis on, the formatted line is appended to the log file. Logly first checks whether the file needs to be rotated. - Every registered sink receives a
LogEventwith the unformatted data.
Logly creates an os.Logger object internally but does not write to it. Messages therefore do not appear in Console.app and cannot be filtered with log stream. They go to standard output (the debug console in Xcode), the log file and the sinks.
Quick Logly example
The following Swift example uses Logly to create an App category, set the minimum level and write a message:
import Logly
import os
extension Logger {
static let app = Logger.custom(category: "App")
}
LoggerConfiguration.shared.currentLogLevel = .info
Logger.app.info("App started")
Console output (default format):
2026-10-03T14:10:52Z - INFO - App - MyApp.swift:8 - App started
Topics of the Logly documentation
The Logly documentation is divided into these pages:
- Getting started: requirements, installation, first message.
- Logging: creating loggers, choosing levels, passing errors, using
async. - Configuration: all settings with default values.
- Output format: placeholders, column widths, colors.
- Log files: location, rotation, cleanup, reading files.
- Crash handling:
LoggerCrashHandler. - Custom sinks: passing messages to your own code.
- Sentry: sending errors and crashes to Sentry.
- FAQ