Basic Setup

After having  installed SwiftyBeaver Logging Framework just add these 2 lines at the top of your AppDelegate.swift:

import SwiftyBeaver
let log = SwiftyBeaver.self

And finally, at the the beginning of your  AppDelegate:didFinishLaunchingWithOptions() add the SwiftyBeaver log destinations (console, file, etc.) you want to use in your whole app:

// add log destinations. at least one is needed!
let console = ConsoleDestination()  // log to Xcode Console
let file = FileDestination()  // log to default swiftybeaver.log file
log.addDestination(console)
log.addDestination(file)

👍 You made it!


Logging Examples

// log with different importance
log.verbose("not so important")  // prio 1, VERBOSE in silver
log.debug("something to debug")  // prio 2, DEBUG in blue
log.info("a nice information")   // prio 3, INFO in green
log.warning("oh no, that won’t be good")  // prio 4, WARNING in yellow
log.error("ouch, an error did occur!")  // prio 5, ERROR in red

// log strings, ints, dates, etc.
log.verbose(123)
log.info(-123.45678)
log.warning(NSDate())
log.error(["I", "like", "logs!"])
log.error(["name": "Mr Beaver", "address": "7 Beaver Lodge"])

Read the below mentioned articles about logging destinations to further tune the output of your SwiftyBeaver logs.

Happy Logging!

Still need help? Contact Us Contact Us