All Projects → vapor-community → swiftybeaver-provider

vapor-community / swiftybeaver-provider

Licence: MIT license
SwiftyBeaver Logging Provider for Vapor, the server-side Swift web framework https://swiftybeaver.com

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to swiftybeaver-provider

Swiftybot
How to create a Telegram, Facebook Messenger, and Google Assistant bot with Swift using Vapor on Ubuntu / macOS.
Stars: ✭ 247 (+671.88%)
Mutual labels:  vapor
fluent-provider
A provider for including Fluent in Vapor applications
Stars: ✭ 13 (-59.37%)
Mutual labels:  vapor
KarmaAPI
Swift API using the Vapor web framework and Turnstile for authentication
Stars: ✭ 20 (-37.5%)
Mutual labels:  vapor
Console Kit
💻 APIs for creating interactive CLI tools.
Stars: ✭ 252 (+687.5%)
Mutual labels:  vapor
VaporTwilioService
Twilio API provider for all your Vapor needs
Stars: ✭ 19 (-40.62%)
Mutual labels:  vapor
VaporGCM
A simple Android GCM/FCM library for Swift/Vapor
Stars: ✭ 25 (-21.87%)
Mutual labels:  vapor
Swiftpackageindex Server
The Swift Package Index is the place to find Swift packages!
Stars: ✭ 228 (+612.5%)
Mutual labels:  vapor
mysql-provider
MySQL provider for the Vapor web framework.
Stars: ✭ 31 (-3.12%)
Mutual labels:  vapor
wkhtmltopdf
Generate and return PDFs from Vapor views
Stars: ✭ 53 (+65.63%)
Mutual labels:  vapor
VaporCRUDRouter
A Rails-inspired extension to Vapor's routing system
Stars: ✭ 58 (+81.25%)
Mutual labels:  vapor
xcode-leaf-color-schemer
https://ashokgelal.com/2017/01/19/leaf_color_schemer_xcode/?ref=github
Stars: ✭ 26 (-18.75%)
Mutual labels:  vapor
web-template
A starting point for web applications
Stars: ✭ 42 (+31.25%)
Mutual labels:  vapor
sqlite-nio
Non-blocking wrapper for libsqlite3-dev using SwiftNIO
Stars: ✭ 33 (+3.13%)
Mutual labels:  vapor
Telegrammer
Telegram Bot - written with Swift 5.2 / NIO, supports Linux, macOS
Stars: ✭ 248 (+675%)
Mutual labels:  vapor
paginator
Offset pagination for Vapor 🗂
Stars: ✭ 67 (+109.38%)
Mutual labels:  vapor
Htmlkit
A type-safe DSL that renders dynamic HTML templates in Swift
Stars: ✭ 229 (+615.63%)
Mutual labels:  vapor
vapor-docs
The Vapor documentation.
Stars: ✭ 46 (+43.75%)
Mutual labels:  vapor
fluent-mysql-driver
🖋🐬 Swift ORM (queries, models, relations, etc) built on MySQL.
Stars: ✭ 69 (+115.63%)
Mutual labels:  vapor
Vapor-JWTAuthorization
Vapor JWT Authorization
Stars: ✭ 45 (+40.63%)
Mutual labels:  vapor
sqlite-kit
Non-blocking SQLite client library with SQL builder built on SwiftNIO
Stars: ✭ 51 (+59.38%)
Mutual labels:  vapor

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 4 on Linux and Mac.

Installation

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

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

Setup

After you've added the SwiftyBeaver Provider package to your project, setting the provider up in code is easy.

You can configure your SwiftyBeaver instance in a pure swift way or using a JSON file like Vapor 2 do,

Register using a pure swift way

import SwiftBeaverProvider

public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services ) throws {
    // ...

    // Setup your destinations
    let console = ConsoleDestination()
    console.minLevel = .info // update properties according to your needs

    let fileDestination = FileDestination()

    // Register the logger
    services.register(SwiftyBeaverLogger(destinations: [console, fileDestination]), as: Logger.self)

    // Optional
    config.prefer(SwiftyBeaverLogger.self, for: Logger.self)
}

Register using a JSON file

First, register the SwiftyBeaverProvider in your configure.swift file.

import SwiftBeaverProvider

public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services ) throws {
    // ...

    // Register providers first
    try services.register(SwiftyBeaverProvider())

    // Optional
    config.prefer(SwiftyBeaverLogger.self, for: Logger.self)
}

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

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

[
  {
    "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

router.get("hello") { req -> Future<String> in
    // Get a logger instance
    let logger: Logger = try req.make(SwiftyBeaverLogger.self)

    // Or
    let logger: Logger = try req.make(Logger.self) // needs config.prefer(SwiftyBeaverLogger.self, for: Logger.self) in configure.swift

    logger.info("Logger info")
    return Future("Hello, world!")
}

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].