MetadataValue

A logging metadata value. Logger.MetadataValue is string, array, and dictionary literal convertible.

Logging.swift:820
enum MetadataValue

MetadataValue provides convenient conformances to ExpressibleByStringInterpolation, ExpressibleByStringLiteral, ExpressibleByArrayLiteral, and ExpressibleByDictionaryLiteral which means that when constructing MetadataValues you should default to using Swift’s usual literals.

Examples:

  • prefer logger.info("user logged in", metadata: ["user-id": "\(user.id)"]) over ..., metadata: ["user-id": .string(user.id.description)])

  • prefer logger.info("user selected colors", metadata: ["colors": ["\(user.topColor)", "\(user.secondColor)"]]) over ..., metadata: ["colors": .array([.string("\(user.topColor)"), .string("\(user.secondColor)")])

  • prefer logger.info("nested info", metadata: ["nested": ["fave-numbers": ["\(1)", "\(2)", "\(3)"], "foo": "bar"]]) over ..., metadata: ["nested": .dictionary(["fave-numbers": ...])])