Adds the powerful logging of SwiftyBeaver to Kitura for server-side Swift 3 on Linux and Mac.
Add this to the Package.swift
of your Kitura project:
dependencies: [
.Package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver-Kitura.git", majorVersion: 1),
//...other packages here
],
import Kitura
import LoggerAPI
import SwiftyBeaver
import SwiftyBeaverKitura
let console = ConsoleDestination()
let logger = SwiftyBeaverKitura(destinations: [console])
Log.logger = logger
Add the SwiftyBeaver logging destinations you want to use, optionally adjust their defaults like format, color, filter or minimum log level and you are ready to log 🙌
// Create a new router
let router = Router()
// Handle HTTP GET requests to /
router.get("/") {
request, response, next in
Log.verbose("not so important")
Log.debug("something to debug")
Log.info("a nice information")
Log.warning("oh no, that won’t be good")
Log.error("ouch, an error did occur!")
response.send("Hello, World!")
next()
}
// Add an HTTP server and connect it to the router
Kitura.addHTTPServer(onPort: 8080, with: router)
// Start the Kitura runloop (this call never returns)
Kitura.run()