Skip to main content

Integration with SwiftLog

SwiftLog Introduction​

SwiftLog is a lightweight logging API for Swift that was created by the Swift Server Working Group. It is under apple's umbrella and is a part of the swift server ecosystem, and works on all platforms that Swift supports. It is slowly becoming the standard for logging in Swift.

Integrating with SwiftLog​

Installation​

To integrate Shipbook with SwiftLog, you need to add the LoggingShipbook package to your project. There are two ways to do this:

Package.swift file dependency​

Add the LoggingShipbook package as a dependency to your Package.swift file.

dependencies: [
package(url: "https://github.com/ShipBook/swift-log-shipbook.git", from: "1.0.0")
]

Xcode integration​

Or under Xcode, go to File -> Swift Packages -> Add Package Dependency and enter the URL for the LoggingShipbook package https://github.com/ShipBook/swift-log-shipbook.git.

Usage​

Then, you can use the LoggingShipbook package to send logs to Shipbook.

import Logging
import LoggingShipbook

let logger = Logger(label: "com.example.MyApp")

ShipBook.start(appId:"YOUR_APP_ID", appKey:"YOUR_APP_KEY")
LoggingSystem.bootstrap(ShipbookLogHandler.init)

Now you can use SwiftLog as you normally would and all logs will be sent to Shipbook.

logger.info("Hello, world!")

Log Levels​

The log levels in SwiftLog are different from those in Shipbook. To map the log levels, you can use the following mapping table:

SwiftLog LevelShipbook Level
traceverbose
debugdebug
infoinfo
noticewarning
warningwarning
errorerror
criticalerror