A macro that outputs logs with formatting anywhere across modules.
.package(url: "https://github.com/to4iki/LogMacro", from: <#version#>)
#logDebug("debug")
#logWarn("warn", category: .tracking)
enum MyError: Error {
case unknown
}
#logFault(MyError.unknown, category: .network)
Set global LogLevel
and configure which logs can be sent on a per-application basis.
LogProcess.shared.setEnabledLogLevel(.warn)
Register a LogReplacingPlugin
for rewrite outgoing log messages.
/// Replace the string "password" with an empty string.
struct PasswordLogReplacingPlugin: LogReplacingPlugin {
func newMessage(from message: String, level: LogLevel) -> String {
message.replacingOccurrences(of: "password", with: "")
}
}
LogProcess.shared.setReplacingPlugin(PasswordLogReplacingPlugin())
Register a LogPostActionPlugin
for perform any processing after the log is post.
/// Print output only when message is `MyError`.
struct MyErrorLogPostActionPlugin: LogPostActionPlugin {
func execute(message: Any, level: LogLevel, file: String, function: String, line: Int) {
guard level >= .fault else {
return
}
guard message is MyError else {
return
}
print("MyErrorLogPostActionPlugin")
}
}
LogProcess.shared.setPostActionPlugins(MyErrorLogPostActionPlugin())
LogMacro is released under the MIT license.