Create custom loggers scoped by subsystem and log level. Provides precise, fine-grained control over logging behavior across different environments.
- Swift 6.1+
- Platforms:
- Linux
- macOS 15+
- iOS 18+
- tvOS 18+
- watchOS 11+
- visionOS 2+
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.
API documentation is available at the following link.
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 MyAppThis 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.
- Build:
swift build - Test:
- local:
swift test - using Docker:
make docker-test
- local:
- Format:
make format - Check:
make check
Pull requests are welcome. Please keep changes focused and include tests for new logic.