MetadataValue

public enum MetadataValue
extension Logger.MetadataValue: Equatable
extension Logger.MetadataValue: ExpressibleByStringLiteral
extension Logger.MetadataValue: CustomStringConvertible
extension Logger.MetadataValue: ExpressibleByStringInterpolation
extension Logger.MetadataValue: ExpressibleByDictionaryLiteral
extension Logger.MetadataValue: ExpressibleByArrayLiteral

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

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": ...])])