This library can be used as an implementation of Apple's swift-log interface that captures console logs from apps or services and sends them to Grafana Loki.
- Supports Linux and all Apple platforms
- Different logging levels such as
trace
,debug
,info
,notice
,warning
,error
andcritical
- Option to send logs as snappy-compressed Protobuf (default) or JSON
- Send logs in batches via
Duration
since batch creation, amount of log entries in batch or a mix of both options
Add LoggingLoki
to the dependencies within your application's Package.swift
file.
.package(url: "https://github.com/lovetodream/swift-log-loki.git", from: "2.0.0"),
Add LoggingLoki
to your target's dependencies.
.product(name: "LoggingLoki", package: "swift-log-loki"),
Go to File
> Add Packages
, enter the Package URL https://github.com/lovetodream/swift-log-loki.git
and press Add Package
.
You can use LoggingLoki as your default Log Handler for swift-log.
import Logging
import LoggingLoki
let processor = LokiLogProcessor(
configuration: LokiLogProcessorConfiguration(lokiURL: "http://localhost:3100")
)
LoggingSystem.bootstrap { label in
LokiLogHandler(label: label, processor: processor)
}
try await withThrowingDiscardingTaskGroup { group in
group.addTask {
// The processor has to run in the background to send logs to Loki.
try await processor.run()
}
}
For more information visit the API reference.
Copyright (c) 2022-present, Timo Zacherl (@lovetodream)
This project contains code written by others not affliated with this project. All copyright claims are reserved by them. For a full list, with their claimed rights, see NOTICE.txt
Swift is a registered trademark of Apple, Inc. Any use of their trademark does not imply any affiliation with or endorsement by them, and all rights are reserved by them.