Skip to content

A vapor logger provider. With level based configuration.

Notifications You must be signed in to change notification settings

pedantix/LevelLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LevelLogger

Logging on the level! For Vapor projects. Logs are the key to both debugging an application as well as monitoring it in production. However what we are interested in during development is often times different from our production interests. Logging by level is one way to deal with this

The Level Logger Comparison Order

The following is just an opinion on what should be the order of leveled debugging. In the future it would probably be good to figure out a way to make this configurable.

var orderValue: Int {
    switch self {
    case.custom: return 6
    case.fatal: return 5
    case.error: return 4
    case.warning: return 3
    case.info: return 2
    case.verbose: return 1
    case.debug: return 0
    }
}

Usage

Within your projects Swift/configure.swift make the following changes

public func configure(
    _ config: inout Config,
    _ env: inout Environment,
    _ services: inout Services
    ) throws {
    // Register providers first
    ...
    try services.register(LevelLoggerProvider()) // Required
    ...
    config.prefer(LevelLogger.self, for: Logger.self) // Required

    // The following is optional, set to debug by default
    if env.isRelease {
        services.register(LogLevel.info)
    } else {
        // optional
        services.register(LogLevel.debug) // Set your non release log level
    }
}

Shameless Plug

This is another shauncodes.com endeavor.

About

A vapor logger provider. With level based configuration.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages