SwiftyBeaver Logging Provider for Vapor
Adds the powerful logging of SwiftyBeaver to Vapor for server-side Swift 3 on Linux and Mac.
Installation
Add this project to the Package.swift
of your Vapor project:
import PackageDescription
let package = Package(
name: "Project",
dependencies: [
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2),
.Package(url: "https://github.com/vapor-community/swiftybeaver-provider.git", majorVersion: 1),
],
exclude: [ ... ]
)
Setup
After you've added the SwiftyBeaver Provider package to your project, setting the provider up in code is easy.
Add to Droplet
First, register the SwiftyBeaverProvider.Provider with your Droplet.
import Vapor
import SwiftyBeaverProvider
let drop = try Droplet()
try drop.addProvider(SwiftyBeaverProvider.Provider.self)
Configure Droplet
Once the provider is added to your Droplet, you can configure it to use the SwiftyBeaver logger. Otherwise you still use the old console logger.
Config/droplet.json
{
"log": "swiftybeaver",
}
Configure Destinations
If you run your application now, you will likely see an error that the SwiftyBeaver configuration file is missing. Let's add that now
Basic
Here is an example of a simple SwiftyBeaver configuration file to configure console destination.
Config/swiftybeaver.json
{
"console": true
}
Here is an example of a SwiftyBeaver configuration file to add all possible destinations.
{
"console": true,
"file": "path/to/log/file",
"platform": {
"appId": "YOUR_APP_ID",
"appSecret": "YOUR_APP_SECRET",
"encryptionKey": "YOUR_ENCRYPTION_KEY"
}
}
Note: It's a good idea to store the SwiftyBeaver configuration file in the Config/secrets folder since it contains sensitive information.
Use
drop.get("/") { request in
drop.log.verbose("not so important")
drop.log.debug("something to debug")
drop.log.info("a nice information")
drop.log.warning("oh no, that won’t be good")
drop.log.error("ouch, an error did occur!")
return "welcome!"
}
The Routes.swift
in the included App folder contains more details. Please also see the SwiftyBeaver destination docs and how to set a custom logging format.
Output to Xcode 8 Console
Learn more about colored logging to Xcode 8 Console.
Output to File
Learn more about logging to file which is great for Terminal.app fans or to store logs on disk.
Output to Cloud & Mac App
Learn more about logging to the SwiftyBeaver Platform during release!
Learn More
Get support via Github Issues, email and our public Slack channel.
License
SwiftyBeaverProvider is released under the MIT License.