Swiftpack.co - Package - vapor-community/swiftybeaver-provider

Swift Version Vapor Version SwiftyBeaver Version Linux Build Status codecov GitHub license

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 dependencies of your Vapor project:

    .Package(url: ".git", majorVersion: 2),
)

or for Swift 4:

  .package(url: "https://github.com/vapor-community/swiftybeaver-provider.git", .upToNextMajor(from: "2.0.0"))

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

The configuration consist of an array of destinations. Here is an example of a simple SwiftyBeaver configuration file to configure console, file and swiftybeaver platform destinations with their required properties.

Config/swiftybeaver.json

[
    {
        "type": "console",
        "format": " $Dyyyy-MM-dd HH:mm:ss.SSS$d $C$L$c: $M"
    },
    {
        "type": "file"
    },
    {
        "type": "platform",        
        "app": "YOUR_APP_ID",
        "secret": "YOUR_SECRET_ID",
        "key": "YOUR_ENCRYPTION_KEY"
    }
]

Aditional options:

| KEY | AVAILABLE FOR | TYPE | OBSERVATION | |-------|---------------|------|-------------| | async | console, file | Bool | | | format | console, file | String | A space must be placed before dollar sign | | levelString.debug | console, file | String | | | levelString.error | console, file | String | | | levelString.info | console, file | String | | | levelString.verbose | console, file | String | | | levelString.warning | console, file | String | | | path | file | String | path to the log file | | minLevel | console, file, platform | String | values: verbose, debug, info, warning, error | | threshold | platform | Int | min: 1, max: 1000 |

Note:
It's a good idea to store the SwiftyBeaver configuration file in the Config/secrets folder since it contains sensitive information.

To get more information about configuration options check the official SwiftyBeaver docs

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

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.

Credits

This package is developed and maintained by Gustavo Perdomo with the collaboration of all vapor community.

License

SwiftyBeaverProvider is released under the MIT License.

Github

link
Stars: 16
Help us keep the lights on

Releases

2.0.0 - Sep 27, 2017

Changes:

  • Rework configuration
  • Multiple destinations of same type
  • Support of format option 1
  • Support of minLevel option 1
  • Support of async option 1
  • Support of levelString option 1
  • Support of threshold option 2
  • Swift 4 support

1 For Console and File destinations 2 For SBPlatform

2.0.0-beta.3 - Sep 25, 2017

Changes since beta 2

  • More tests and coverage
  • Added resolver protocol
  • Update docs

2.0.0-beta.2 - Sep 22, 2017

In this release:

  • Rework configuration
  • Multiple destinations of same type
  • Support of format config 1
  • Support of minLevel config 1
  • Support of async config 1
  • Support of levelString config 1
  • Support of threshold config 2
  • Swift 4 support

Missing:

  • More tests + coverage
  • Update docs

1.0.2 - Jun 28, 2017

Show log messages properly according to LogLevel

1.0.1 - Jun 14, 2017

Deleted example and all unnecessary code for this package