Git Product home page Git Product logo

swiftybeaver-vapor's Introduction

SwiftyBeaver Logging Provider for Vapor

Swift Vapor 3.x SwiftyBeaver 1.x Slack

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

Installation

Add this to the Package.swift of your Vapor project:

dependencies: [
    .package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver-Vapor.git", from: "1.1.0")),
	//...other packages here
],

Setup

In configure.swift:

import SwiftyBeaverVapor
import SwiftyBeaver

/// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
    
    // ...

    // console logging 
    let consoleDestination = ConsoleDestination()
    try services.register(SwiftyBeaverProvider(destinations: [consoleDestination]))
    
    // OR console and cloud platform logging
    let consoleDestination = ConsoleDestination()
    let cloudDestination = SBPlatformDestination(appID: "xxx", appSecret: "xxxxxx", encryptionKey: "xxxxx")
    try services.register(SwiftyBeaverProvider(destinations: [consoleDestination, cloudDestination]))

    config.prefer(SwiftyBeaverVapor.self, for: Logger.self)

    // ...
}

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

For example, you can log requests as they come in.

func index(_ req: Request) throws -> Future<[Foo]> {

    let logger = try? req.sharedContainer.make(Logger.self)
    logger?.log(req.description, at: .verbose, file: #file, function: #function, line: #line, column: #column)

    return Foo.query(on: req).all()
}

For more information 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

swiftybeaver-demo1

Learn more about logging to the SwiftyBeaver Platform during release!

Learn More

Get support via Github Issues, email and our public Slack channel.

License

SwiftyBeaverVapor is released under the MIT License.

swiftybeaver-vapor's People

Contributors

skreutzberger avatar martinw avatar tomattoz avatar foscomputerservices avatar addisonwebb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.