Skip to main content

Integration with SwiftyBeaver

SwiftyBeaver Introduction

SwiftyBeaver is a Colorful, flexible, lightweight logging for Swift. With Shipbook you have visibility of all your app's issues and logs from remote and you can easily integrate Shipbook with SwiftyBeaver for a comprehensive solution.

Originally, SwiftyBeaver supported logging to a cloud service; however, this feature has been deprecated. Now, Shipbook can be used for cloud-based logging.

Integrating with SwiftyBeaver

Create a new file class called ShipbookDestination

Just add the following code and it will work out of the box with timber.

import ShipBookSDK
import SwiftyBeaver

public class ShipbookDestination: BaseDestination {
override public func send(_ level: SwiftyBeaver.Level, msg: String, thread: String, file: String,
function: String, line: Int, context: Any? = nil) -> String? {

let shipbookSeverity: Severity = {
switch(level) {
case .verbose: return Severity.Verbose
case .debug: return Severity.Debug
case .info: return Severity.Info
case .warning: return Severity.Warning
case .error: return Severity.Error
}
}()

Log.message(msg: msg, severity: shipbookSeverity, tag: thread, function: function, file: file, line: line)
return super.send(level, msg: msg, thread: thread, file: file, function: function, line: line)
}
}

add Shipbook destination to SwiftyBeaver:

Add that near the top of your AppDelegate.swift file:

import ShipBookSDK
import SwiftyBeaver
let log = SwiftyBeaver.self

Add to AppDelegate:didFinishLaunchingWithOptions():

let shipbook = ShipbookDestination()
log.addDestination(shipbook)

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

log.verbose("Verbose")
log.debug("Debug")
log.info("Info")
log.warning("Warning")
log.error("Error")

That's it! You're all set to use SwiftyBeaver with Shipbook.