https://github.com/binarybirds/swift-log-env
Create custom loggers using a subsystem identifier and a log level.
https://github.com/binarybirds/swift-log-env
Last synced: about 1 month ago
JSON representation
Create custom loggers using a subsystem identifier and a log level.
- Host: GitHub
- URL: https://github.com/binarybirds/swift-log-env
- Owner: BinaryBirds
- License: mit
- Created: 2024-02-27T17:03:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-27T17:21:17.000Z (over 2 years ago)
- Last Synced: 2025-03-19T13:17:13.332Z (about 1 year ago)
- Language: Shell
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Swift Logging Environment
Create custom loggers scoped by subsystem and log level. Provides precise, fine-grained control over logging behavior across different environments.
[]( https://github.com/binarybirds/swift-log-env/releases/tag/2.0.0)
## Requirements


- 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:
```swift
.package(url: "https://github.com/binarybirds/swift-log-env", from: "2.0.0"),
```
Then add `LoggingEnvironment` to your target dependencies:
```swift
.product(name: "LoggingEnvironment", package: "swift-log-env"),
```
Update the packages and you are ready.
## Usage
[](https://binarybirds.github.io/swift-log-env)
API documentation is available at the following link.
## Basic example
```swift
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](https://github.com/BinaryBirds/swift-log-env/pulls) are welcome. Please keep changes focused and include tests for new logic.