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": ...])])
-
A metadata value which is a
String.Because
MetadataValueimplementsExpressibleByStringInterpolation, andExpressibleByStringLiteral, you don’t need to type.string(someType.description)you can use the string interpolation"\(someType)".Declaration
Swift
case string(String) -
A metadata value which is some
CustomStringConvertible.Declaration
Swift
case stringConvertible(CustomStringConvertible) -
A metadata value which is a dictionary from
StringtoLogger.MetadataValue.Because
MetadataValueimplementsExpressibleByDictionaryLiteral, you don’t need to type.dictionary(["foo": .string("bar \(buz)")]), you can just use the more natural["foo": "bar \(buz)"].Declaration
Swift
case dictionary(Metadata) -
A metadata value which is an array of
Logger.MetadataValues.Because
MetadataValueimplementsExpressibleByArrayLiteral, you don’t need to type.array([.string("foo"), .string("bar \(buz)")]), you can just use the more natural["foo", "bar \(buz)"]. -
Declaration
Swift
public typealias StringLiteralType = String -
Declaration
Swift
public init(stringLiteral value: String) -
Declaration
Swift
public var description: String { get } -
Declaration
Swift
public typealias Key = String -
-
-
-
View on GitHub
Install in Dash
MetadataValue Enumeration Reference