mirror of
https://github.com/apple/swift-log
synced 2026-11-25 03:57:48 +00:00
8f634e4e682819a9aa857fca8c88ef899fb64d75
I've added support for FreeBSD. I've only tested this PR on FreeBSD, but I believe it should also work on OpenBSD. ### Motivation: closes #372 Also, [Swift on FreeBSD preview toolchain](https://forums.swift.org/t/swift-on-freebsd-preview/83064) is now available. ### Modifications: - changed pthread-related code for *BSD - changed `Glibc.stdout` and `Glibc.stderr` for *BSD because they are non-optional on *BSD ### Result: swift-log and packages depending on it will be usable on FreeBSD. ### Checks: I tested it with `swift build` and `swift test`. All tests have passed. ```console $ swift test ... Test Suite 'All tests' passed at 2025-11-07 04:29:34.003 Executed 0 tests, with 0 failures (0 unexpected) in 0.0 (0.0) seconds ... ✔ Test run with 52 tests in 7 suites passed after 0.309 seconds. ``` Environment: ```console $ uname -a FreeBSD Coconut-rhinoceros-beetle 15.0-BETA4 FreeBSD 15.0-BETA4 releng/15.0-n280841-a7707f2a3bf4 GENERIC amd64 $ swift --version Swift version 6.3-dev (LLVM bff1370bd79c983, Swift 57cf4ce563f700b) Target: x86_64-unknown-freebsd14.3 Build config: +assertions ``` Swift toolchain is from https://forums.swift.org/t/swift-on-freebsd-preview/83064. --------- Co-authored-by: Franz Busch <f.busch@apple.com>
SwiftLog
This repository contains a logging API implementation for Swift. SwiftLog provides a unified, performant, and ergonomic logging API that can be adopted by libraries and applications across the Swift ecosystem.
- 📚 Documentation and tutorials are available on the Swift Package Index
- 🚀 Contributions are welcome, please see CONTRIBUTING.md
- 🪪 License is Apache 2.0, repeated in LICENSE.txt
- 🔒 Security issues should be reported via the process in SECURITY.md
- 🔀 Available Logging Backends: SwiftLog is an API package - you'll want to choose from the many community-maintained logging backends for production use
Quick Start
The following snippet shows how to add SwiftLog to your Swift Package:
// swift-tools-version: 6.1
import PackageDescription
let package = Package(
name: "YourApp",
dependencies: [
.package(url: "https://github.com/apple/swift-log", from: "1.6.0")
],
targets: [
.target(
name: "YourApp",
dependencies: [
.product(name: "Logging", package: "swift-log")
]
)
]
)
Then start logging:
import Logging
// Create a logger
let logger = Logger(label: "com.example.YourApp")
// Log at different levels
logger.info("Application started")
logger.warning("This is a warning")
logger.error("Something went wrong", metadata: ["error": "\(error)"])
// Add metadata for context
var requestLogger = logger
requestLogger[metadataKey: "request-id"] = "\(UUID())"
requestLogger.info("Processing request")
Available log handler backends
The community has built numerous specialized logging backends.
A great way to discover available log backend implementations is searching the
Swift Package Index
for the swift-log keyword.
Description
Mirror of github.com/apple/swift-log
3.3 MiB
0 Stars
1 Watchers
0 Forks
Languages
Swift
97.5%
CMake
2.5%