Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexander-ignition/oslogging
swift-log + os.log
https://github.com/alexander-ignition/oslogging
oslog swift swift-log swift-logger
Last synced: about 5 hours ago
JSON representation
swift-log + os.log
- Host: GitHub
- URL: https://github.com/alexander-ignition/oslogging
- Owner: Alexander-Ignition
- License: mit
- Created: 2019-10-19T12:48:25.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-14T15:14:46.000Z (almost 3 years ago)
- Last Synced: 2024-09-16T16:06:39.455Z (2 months ago)
- Topics: oslog, swift, swift-log, swift-logger
- Language: Swift
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OSLogging
[![SPM compatible](https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat)](https://swift.org/package-manager)
[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/Alexander-Ignition/OSLogging/blob/master/LICENSE)[`OSLog`](https://developer.apple.com/documentation/os/logging) logging backend for [`swift-log`](https://github.com/apple/swift-log)
- [WWDC 2016 Unified Logging and Activity Tracing](https://developer.apple.com/videos/play/wwdc2016/721/)
- logs can be seen in Console.app## Features
- [x] Configure `OSLog`
- [x] Mapping logging levels of `Logger.Level` to `OSLogType`
- [x] Customize metadata formatter## Instalation
Add dependency to `Package.swift`...
```swift
.package(url: "https://github.com/Alexander-Ignition/OSLogging", from: "1.0.0"),
```... and your target
```swift
.target(name: "ExampleApp", dependencies: ["OSLogging"]),
```## Usage
Override `LoggingSystem` with default `OSLog`.
```swift
LoggingSystem.bootstrap { _ in OSLogHandler() }let logger = Logger(label: "com.example.app")
logger.info("i found you!")
// 2019-10-20 08:47:35.498086+0300 ExampleApp[6533:150683] i found you!
```Сhoose subsystems and categories for different parts of the application
```swift
let logger = Logger(label: "com.exaple.app") { label in
OSLogHandler(subsystem: label, category: "auth")
}logger.info("loose control")
// 2019-10-20 08:47:35.498582+0300 ExampleApp[6533:150683] [auth] loose control
```Custom metadata format
```swift
var logger = Logger(label: "com.exaple.app") { label in
var hanlder = OSLogHandler(subsystem: label, category: "session")
hanlder.formatter = { metadata in
metadata.map { "\($0):\($1)" } .joined(separator: ", ")
}
return hanlder
}
logger[metadataKey: "request-id"] = "1"
logger[metadataKey: "session-id"] = "a"logger.warning("catch me if you can")
// 2019-10-20 08:47:35.499106+0300 ExampleApp[6533:150683] [session] session-id:a, request-id:1 catch me now```