When the MaxLogLevelNone trait is enabled, all log-emitting methods on Logger (trace, debug, …, critical, and log(level:)) compile out to empty bodies — see for example the critical method's #if !MaxLogLevelNone guard at https://github.com/apple/swift-log/blob/main/Sources/Logging/Logger.swift#L989. The intent of the trait is to "achieve zero runtime overhead" for log levels that are turned off, with MaxLogLevelNone turning off everything.
However, the metadata subscript setter at https://github.com/apple/swift-log/blob/main/Sources/Logging/Logger.swift#L322-L330 is not guarded by the same trait check:
public subscript(metadataKey metadataKey: String) -> Logger.Metadata.Value? {
get {
self.handler[metadataKey: metadataKey]
}
set {
self.handler[metadataKey: metadataKey] = newValue
}
}
So code like logger[metadataKey: "user-id"] = "\(id)" still goes through the underlying LogHandler even when no log statement could ever observe that metadata.
We could wrap the setter body in #if !MaxLogLevelNone, mirroring the pattern used by the level-specific log methods. It might also be worth considering whether the logLevel setter at https://github.com/apple/swift-log/blob/main/Sources/Logging/Logger.swift#L338-L346 should also be modified.
When the
MaxLogLevelNonetrait is enabled, all log-emitting methods onLogger(trace, debug, …, critical, andlog(level:)) compile out to empty bodies — see for example the critical method's#if !MaxLogLevelNoneguard at https://github.com/apple/swift-log/blob/main/Sources/Logging/Logger.swift#L989. The intent of the trait is to "achieve zero runtime overhead" for log levels that are turned off, withMaxLogLevelNoneturning off everything.However, the metadata subscript setter at https://github.com/apple/swift-log/blob/main/Sources/Logging/Logger.swift#L322-L330 is not guarded by the same trait check:
So code like
logger[metadataKey: "user-id"] = "\(id)"still goes through the underlyingLogHandlereven when no log statement could ever observe that metadata.We could wrap the setter body in
#if !MaxLogLevelNone, mirroring the pattern used by the level-specific log methods. It might also be worth considering whether thelogLevelsetter at https://github.com/apple/swift-log/blob/main/Sources/Logging/Logger.swift#L338-L346 should also be modified.