Skip to main content

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:

FeatureIn shortPage
Five log levelsdebug, info, warning, error, fault with a configurable minimum levelLogging
CategoriesOne logger per area, e.g. Network or DatabaseLogging
Synchronous and async APIEvery log method and every setting exists in both variantsLogging, Configuration
Central configurationOne thread-safe object, LoggerConfiguration.sharedConfiguration
Output formatFormat string with placeholders, fixed column widths, ANSI colorsOutput format
Log fileWriting to a file, rotation by size and age, cleanup of old filesLog files
Background processingFormatting and writing on a dedicated serial queueConfiguration
Crash handlingLogs uncaught exceptions and reports fatal signalsCrash handling
Custom destinations (sinks)Pass structured events, including the Error, to your own codeCustom sinks
Sentry integrationOptional LoglySentry productSentry

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 the Sentry package trait. Without the trait the module is empty and sentry-cocoa is not fetched.

In Logly, a log message goes through these steps:

  1. You call e.g. logger.info("…").
  2. Logly reads a snapshot of the configuration and compares the message level with currentLogLevel. If it is lower, the call ends here.
  3. If asynchronousLogging is on, the following steps run on a serial background queue, otherwise directly on the calling thread.
  4. The message is formatted according to logFormat and printed with print, colored if enabled.
  5. If logToFile is on, the formatted line is appended to the log file. Logly first checks whether the file needs to be rotated.
  6. Every registered sink receives a LogEvent with the unformatted data.
No output to unified logging

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: