Swiftpack.co -  didactek/deft-log as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
didactek/deft-log
Allow libraries to expose Swift Log logging options to applications.
.package(url: "https://github.com/didactek/deft-log.git", from: "0.0.1")

DeftLog

A factory for building swift-log Loggers while adding centralized control over logLevel. Can be used by libraries to surface their logging options to applications.

Need

DeftLog provides a way for a program to configure log levels for all DeftLog-enabled libraries at logger label granularity.

In swift-log, the decision about whether to log a message is made by each logger; the Logger's extension checks the message against each instance's logLevel and does not forward the message to the log hander if the message does not reach the configured threshold. LogLevel is intended to be part of the Logger state; implementers of alternate Loggers are discouraged from centrally adjusting logLevel.

Swift Log doesn't suggest any particular pattern for setting logLevel. For implementors of package libraries who want to allow library consumers to adjust logLevel, they are left on their own to plumb the setting of logLevel into private Loggers. This library offers a pattern where the main runtime can describe desired log levels early in execution, and then the library's Logger factory will offer Loggers to the implmentor that default to the logLevel specified at the executable level.

Usage

Configuring

Near the start of the program, before libraries start requesting their loggers, set the configuration:

DeftLog.settings = [
    ("com.didactek.deft-log", .critical),
    ("com.didactek.deft-mcp2221.usb", .trace),
    ("com.didactek.deft-mcp2221", .debug),
]

Obtaining Loggers

let logger = DeftLog.logger(label: "com.didactek.deft-mcp2221.hidapi") // .debug

The settings are searched from start to end, looking for the first match against a label prefix. If no match is found, the default logLevel (as set by the initializer) is unchanged .

DeftLog.logger(label:) returns a Logger created from swift-log. It will be connnected to the bootstrapped log handler backend in the usual manner.

GitHub

link
Stars: 0
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Dependencies

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API