目录
目录README.md

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.

关于
32.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号