Skip to main content

Getting started

This guide adds Logly to your project and writes the first log message to the console and to a file.

Requirements for Logly​

To use Logly, your project needs:

  • iOS 16 or macOS 13 as the minimum deployment target
  • Swift 6.1 or later (Swift tools version 6.1)
  • Swift Package Manager

Installing Logly​

Adding Logly in Xcode​

This is how you add Logly in Xcode:

  1. Choose File > Add Package Dependencies….
  2. Enter https://github.com/Flexible-Universe/Logly.
  3. Choose the version and add the Logly product to your app target.

You only need the LoglySentry product for the Sentry integration.

Adding Logly in a Package.swift​

In a Package.swift you add Logly as a dependency and add the Logly product to your target:

Package.swift
// swift-tools-version: 6.1
import PackageDescription

let package = Package(
name: "MyFeature",
platforms: [.iOS(.v16), .macOS(.v13)],
dependencies: [
.package(url: "https://github.com/Flexible-Universe/Logly", from: "1.1.0"),
],
targets: [
.target(
name: "MyFeature",
dependencies: [
.product(name: "Logly", package: "Logly"),
]
),
]
)

from: "1.1.0" allows every version from 1.1.0 up to, but not including, 2.0.0.

First use of Logly​

1. Import the modules for Logly​

For Logly you import the Logly module and Apple's os module:

import Logly
import os
import os is required

Loggers are created with Logger.custom(category:). Logger is the type from Apple's os module. Logly does not re-export that import. Without import os (or import OSLog) the compiler reports cannot find 'Logger' in scope.

2. Create a Logly logger​

You create a Logly logger as a static property in an extension of Logger:

extension Logger {
static let app = Logger.custom(category: "App")
}

Logger.custom(category:) returns a LogCategory value. Create it once and use it everywhere.

3. Configure Logly at app startup​

Without any configuration Logly already writes to the console and to app_log.txt in the temporary directory. For your own file, create the folder yourself, because Logly does not create missing folders. The following example configures Logly in the init() of a SwiftUI app:

import SwiftUI
import Logly
import os

@main
struct MyApp: App {
init() {
let config = LoggerConfiguration.shared

let logsDirectory = FileManager.default
.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
.appendingPathComponent("Logs")
try? FileManager.default.createDirectory(at: logsDirectory,
withIntermediateDirectories: true)

config.logFilePath = logsDirectory.appendingPathComponent("app.log")

#if DEBUG
config.currentLogLevel = .debug
#else
config.currentLogLevel = .info
config.enableANSIColors = false
#endif

Logger.app.info("App started")
}

var body: some Scene {
WindowGroup {
ContentView()
}
}
}

4. Write messages with Logly​

With Logly you write messages at the five levels like this:

Logger.app.debug("Configuration loaded")
Logger.app.info("User signed in")
Logger.app.warning("Cache almost full")
Logger.app.error("Saving failed")
Logger.app.fault("Database corrupted")

Logly prints the messages to the console like this:

2026-10-03T14:10:52Z - DEBUG - App - ContentView.swift:12 - Configuration loaded
2026-10-03T14:10:52Z - INFO - App - ContentView.swift:13 - User signed in

The same lines, without color codes, are in app.log.

Color codes in the Xcode console

The Xcode debug console does not render ANSI color codes as colors. It shows control sequences such as [0;32m instead. In that case set config.enableANSIColors = false. In a terminal (e.g. with swift run) the colors work.

Next steps with Logly​

These pages go deeper into Logly: