GitHunt
BI

BinaryBirds/swift-log-env

Create custom loggers using a subsystem identifier and a log level.

Swift Logging Environment

Create custom loggers scoped by subsystem and log level. Provides precise, fine-grained control over logging behavior across different environments.

Release: 2.0.0

Requirements

Swift 6.1+
Platforms: macOS, iOS, tvOS, watchOS, visionOS

  • Swift 6.1+
  • Platforms:
    • Linux
    • macOS 15+
    • iOS 18+
    • tvOS 18+
    • watchOS 11+
    • visionOS 2+

Installation

Use Swift Package Manager; add the dependency to your Package.swift file:

.package(url: "https://github.com/binarybirds/swift-log-env", from: "2.0.0"),

Then add LoggingEnvironment to your target dependencies:

.product(name: "LoggingEnvironment", package: "swift-log-env"),

Update the packages and you are ready.

Usage

DocC API documentation

API documentation is available at the following link.

Basic example

import LoggingEnvironment

let libLogger = Logger.subsystem("my-lib", .notice)
let appLogger = Logger.subsystem("my-app", .notice)

// LOG_LEVEL=info MY_LIB_LOG_LEVEL=trace swift run MyApp

This imports LoggingEnvironment and creates two loggers scoped to my-lib and my-app with a default .notice level. At runtime, environment variables override these levels: LOG_LEVEL sets a global minimum, while MY_LIB_LOG_LEVEL applies a more specific level to the my-lib subsystem, enabling per-subsystem logging control without code changes.

Development

  • Build: swift build
  • Test:
    • local: swift test
    • using Docker: make docker-test
  • Format: make format
  • Check: make check

Contributing

Pull requests are welcome. Please keep changes focused and include tests for new logic.

Languages

Swift87.3%Makefile10.8%Dockerfile1.8%

Contributors

MIT License
Created February 27, 2024
Updated February 9, 2026
BinaryBirds/swift-log-env | GitHunt