Log is a lightweight logging framework written in Swift.

What's New



Released on 2024-01-19


  • Make the logLevel property changeable
    • Added in Pull Request #5.
  • Add files to comply with community standards
    • Added in Pull Request #4.
  • Update GitHub Actions workflow
    • Added in Pull Request #3.
  • Hide IOSWriter & IConsoleWriter from the public interface
    • Added in Pull Request #2.

Log: A lightweight logging framework written in Swift


License Swift Compatibility Platform Compatibility CI CodeCov GitHub release; latest by date GitHub commit activity


Log is a lightweight logging framework written in Swift.


Create a logger instance

First, you need to create an instance of IPrinter that prints messages to a specific output, such as XCode's console or the Console app. The log package provides predefined printers for printing messages in the XCode console (ConsolePrinter) and the system console (OSPrinter). You can also create your own printer. To do this, your object must conform to IPrinterStrategy and implement the necessary methods.

import Log

let osPrinter = OSPrinter()
let consolePrinter = ConsolePrinter()

Second, create a Logger instance and pass these printers as initialization parameters while defining a log level. The log level determines the level of log messages to print. If the log level is set to a specific level, all messages with different log levels will be ignored. To print all messages, use .all.

let log = Logger(
    printers: [osPrinter, consolePrinter],
    logLevel: .all
log.error(message: "test message")

Formatting a message

Each instance of IPrinter has an array of formatters that are responsible for formatting input messages. The log package provides predefined prefix and timestamp formatters. To use these, you need to pass them to an initializer of a printer.

let osPrinter = OSPrinter(formatters: [PrefixFormatter(name: "your prefix here")])
log.fault(message: "message") // "🚨🚨🚨 [your prefix here] => message"

Here is a list of predefined formatters:

Formatters Description
PrefixLogFormatter Add a specified prefix to a printed message
TimestampLogFormatter Add a timestamp before a printed message based on a date format

Custom formatters

If you want to create a custom message formatter, your object must conform to the ILogFormatter protocol and implement the necessary methods.

struct MyCustomMessageFormatter: ILogFormatter {
    func format(message: String, with logLevel: LogLevel) -> String {
        // your implementation here


  • iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 7.0+ / visionOS 1.0+
  • Xcode 14.0
  • Swift 5.7


Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but log does support its use on supported platforms.

Once you have your Swift package set up, adding log as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/space-code/log.git", .upToNextMajor(from: "1.0.0"))


  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.


Bootstrapping development environment

make bootstrap

Please feel free to help out with this project! If you see something that could be made better or want a new feature, open up an issue or send a Pull Request!


Nikita Vasilev, nv3212@gmail.com


log is available under the MIT license. See the LICENSE file for more info.


  • Swift Tools 5.9.0
View More Packages from this Author


  • None
Last updated: Sun Mar 17 2024 02:25:28 GMT-0900 (Hawaii-Aleutian Daylight Time)