apple / apple/swift-log

Add Logger.withMetadata() function to create a logger with multiple metadata values

Open
#321 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
4k
Forks
344
Avg merge
1d 15h
Merged PRs (30d)
4

Description

### Expected behavior
Let’s say I have an existing Logger.Metadata struct I want to add to a Logger as metadata. It doesn’t seem like there is a simple function like `Logger.withMetadata(metadata: Logger.Metadata)` I can use. This means I have to iterate through every kv pair in my Logger.Metadata and add it to the logger with `logger[key] = value`, which is verbose.

(this `withMetadata` pattern is common in many logging libraries, so it would be great to have this as a convenience function in swift-log as well)

### Actual behavior
N/A

### Steps to reproduce
N/A

### If possible, minimal yet complete reproducer code (or URL to code)
N/A

### SwiftLog version/commit hash

`1.6.1/9cb486020ebf03bfa5b5df985387a14a98744537`

### Swift & OS version (output of `swift --version && uname -a`)
```
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
```

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing Logger.Metadata type and Logger metadata APIs in swift-log, then inspect how similar convenience methods are tested. Done means providing a Logger.withMetadata(metadata:) API that accepts multiple metadata values without requiring callers to iterate through key-value pairs, with tests covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
observability-sre
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.