Skip to content

Commit

Permalink
Add test for withMetadata convenience function
Browse files Browse the repository at this point in the history
  • Loading branch information
gabbifish committed Sep 13, 2024
1 parent cea90dd commit 4e2911c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Tests/LoggingTests/LoggingTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,25 @@ class LoggingTest: XCTestCase {
"nested-list": ["l1str", ["l2str1", "l2str2"]]])
}

func testWithMetadata() {
let testLogging = TestLogging()
LoggingSystem.bootstrapInternal { testLogging.make(label: $0) }

var logger = Logger(label: "\(#function)")
let metadata: Logger.Metadata = [
"foo": ["bar", "buz"],
"empty-list": [],
"nested-list": ["l1str", ["l2str1", "l2str2"]]
]
logger.withMetadata(metadata: metadata)
logger.info("hello world!")
testLogging.history.assertExist(level: .info,
message: "hello world!",
metadata: ["foo": ["bar", "buz"],
"empty-list": [],
"nested-list": ["l1str", ["l2str1", "l2str2"]]])
}

// Example of custom "box" which may be used to implement "render at most once" semantics
// Not thread-safe, thus should not be shared across threads.
internal final class LazyMetadataBox: CustomStringConvertible {
Expand Down

0 comments on commit 4e2911c

Please sign in to comment.