Skip to content

SwiftyBeaver/SwiftyBeaver-Kitura

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftyBeaver Logging Provider for IBM Kitura

Language Swift 3 Kitura 1.7.x Slack Status

Adds the powerful logging of SwiftyBeaver to Kitura for server-side Swift 3 on Linux and Mac.

Installation

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
],

Setup

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 🙌

Use

// 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()