---
title: "#142: Colorful Logging with SwiftyBeaver 🐺"
url: https://littlebitesofcocoa.com/142-colorful-logging-with-swiftybeaver
author: Jake Marsh
date: 2015-12-08
published: 2015-12-08
topics: ["Libraries","Debugging"]
description: "Today we're looking at SwiftyBeaver, a library from Sebastian Kreutzberger that aims to improve Xcode's logging capabilities."
---

# #142: Colorful Logging with SwiftyBeaver 🐺

By Jake Marsh, December 8, 2015. HTML: https://littlebitesofcocoa.com/142-colorful-logging-with-swiftybeaver

Today we're looking at _SwiftyBeaver_, a library from [Sebastian Kreutzberger](https://github.com/skreutzberger) that aims to improve **Xcode's** logging capabilities. Let's dive in.

After adding the library to our project we'll need to import the library in our **AppDelegate**. We'll also need to create a global **log** reference we can use throughout our **app**:

``` swift
import SwiftyBeaver
let log = SwiftyBeaver.self
```

Then we'll need to tell _SwiftyBeaver_ to log somewhere, let's set it up to log to **Xcode's** console <i>and</i> a log file:

``` swift
let console = ConsoleDestination()
let file = FileDestination()

log.addDestination(console)
log.addDestination(file)
```

_SwiftyBeaver_ is built around the concept of "**destinations**". Here we're adding one for the **Xcode** console, then another to log to a file in our app's **documents directory.**

Now, we can use our global **log** reference to log **messages**. There's **functions** for each of the different **levels**. Each will log its level in its own <span style='color: #0A33FF'>color:</span>

``` swift
log.verbose("Nothing really happened") // gray
log.debug("A thing happened") // blue
log.info("A good thing happened") // green
log.warning("A probably bad thing happened") // yellow
log.error("A definitely bad thing happened") // red
```

Both built-in **destinations** have a ton of configuration options allowing us to customize how we'd like our **logs** to behave. We can customize the **format** of log statements or change a **file destination's location**, we can even define our own **destinations** if needed!

More info about _SwiftyBeaver_ can be found at [git.io/swiftybeaver](http://git.io/swiftybeaver)

<img src='https://media.littlebitesofcocoa.com/bite-assets/142-colorful-logging-with-swiftybeaver-preview.png' style='max-width: 709px;' />
