Using SwiftyBeaver

Just recently I've tried out out a (relatively) new logging frameworks for iOS called SwiftyBeaver. It's currently in private beta and already looks very promising.

As all my side projects are open source by default I'm, of course again, running into special challenges in regards of disclosing the full source code vs. keeping the private parts (aka keys and secrets) secret.

While keeping your credentials safe on an assembly level is a challenge still to be solved, it's feasible to keep it safe on a code-basis level without too much effort, it's just a matter of doing it (right).

In my particular app I've decided to break down the problem into two very simple problems where the user (aka developer) either has SwiftyBeaver or he does not.

If the user wants to use SwiftyBeaver there a few easy steps to perform to get logging with SwiftyBeaver to work inside your app. First create a folder called swiftybeaver it will contain files needed to get SwiftyBeaver working dynamically.

mkdir swiftybeaver && touch swiftybeaver/vars.sh
chmod +x swiftybeaver/vars.sh # make them executable

This folder will be added to your .gitignore.

echo "swiftybeaver/*" >> .gitignore

Now grad the editor of your choice and add the following variable exports to vars.sh:

export SB_APP_ID={swifty beaver app id}
export SB_APP_SECRET={swifty beaver app secret}
export SB_ENCRYPTION_KEY={swifty beaver encryption key}

Almost done, just grab the swiftybeaver.sh script which will be in charge of creating the Plist needed to carry the SwiftyBeaver credentials and making your app authenticate itself against the platform, please run this inside your projects root folder:

curl https://gist.githubusercontent.com/kimar/48f674b6ec2b9230550ee11e4a60b00d/raw/1f5084135b209420b14c548e58a928e8c8a386ff/swiftybeaver.sh -o swiftybeaver.sh && chmod +x swiftybeaver.sh

Now hook it all up in Xcode

Create a new Run Script phase for your target and let it call swiftybeaver.sh:

swiftbeaver-0.png

Inside your app

What I did to keep things as dynamic as possible was creating a Struct to keep certain environment variables e.g. the SwiftyBeaver credentials. In my project this file is called Environment.swift:

This will then used where SwiftyBeaver is initialized (aka. the AppDelegate).

Let's go loggin'

Build your app and your logs should appear inside the SwiftyBeaver Mac App automagically! 🎉 In case you want to check it our, just register for the private beta at SwiftyBeaver and check out the relayable iOS app here.

swiftbeaver-1.png