Created
June 15, 2020 14:08
-
-
Save jordanebelanger/1a61e460276b5332204723f928b4155e to your computer and use it in GitHub Desktop.
Async logging of error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import NIO | |
import Logging | |
extension EventLoopFuture { | |
func whenFailureLog( | |
level: Logger.Level = .error, | |
_ message: @escaping @autoclosure () -> Logger.Message, | |
using logger: Logger, | |
errorDescriptionMetadataKey: String = "reason", | |
metadata: @escaping @autoclosure () -> Logger.Metadata? = nil, | |
file: String = #file, function: String = #function, line: UInt = #line | |
) { | |
self.whenFailure { error in | |
var logger = logger | |
logger[metadataKey: errorDescriptionMetadataKey] = "\(error)" | |
logger.log(level: level, message(), metadata: metadata(), file: file, function: function, line: line) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment