From 41462ded26121b68f5360015e534416308e9dc47 Mon Sep 17 00:00:00 2001 From: Wojciech Nagrodzki <278594+wnagrodzki@users.noreply.github.com> Date: Tue, 21 Aug 2018 22:11:09 +0200 Subject: [PATCH] Redesign LogLevel to conform to syslog severity levels --- Logger/Logger.swift | 47 +++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/Logger/Logger.swift b/Logger/Logger.swift index 128ba6a..2f76349 100644 --- a/Logger/Logger.swift +++ b/Logger/Logger.swift @@ -58,33 +58,46 @@ public protocol Logger { } /// Log level controls the conditions under which a message should be logged. +/// - note: [RFC5424](https://www.rfc-editor.org/info/rfc5424) public enum LogLevel: Int { - /// Use this level to capture information about things that might result a failure. - case `default` + /// System is unusable. + case emergency = 0 - /// Use this level to capture information that may be helpful, but isn’t essential, for troubleshooting errors. - case info + /// Action must be taken immediately. + case alert = 1 - /// Use this level to capture information that may be useful during development or while troubleshooting a specific problem. - case debug + /// Critical conditions. + case critical = 2 - /// Use this log level to capture process-level information to report errors in the process. - case error + /// Error conditions. + case error = 3 - /// Use this level to capture system-level or multi-process information to report system errors. - case fault + /// Warning conditions. + case warning = 4 + + /// Normal but significant conditions. + case notice = 5 + + /// Informational messages. + case informational = 6 + + /// Debug-level messages. + case debug = 7 } extension LogLevel: LogStringConvertible { public var logDescription: String { switch self { - case .default: return "Default" - case .info: return "Info" - case .debug: return "Debug" - case .error: return "Error" - case .fault: return "Fault" + case .emergency: return "emerg" + case .alert: return "alert" + case .critical: return "crit" + case .error: return "err" + case .warning: return "warning" + case .notice: return "notice" + case .informational: return "info" + case .debug: return "debug" } } } @@ -95,11 +108,11 @@ extension Logger { /// /// - Parameters: /// - object: The object to be logged. - /// - level: The log level. If unspecified, the `default` log level is used. + /// - level: The log level. /// - file: **Do not provide a custom value.** The path to the file log method is called from. /// - line: **Do not provide a custom value.** The line number log method is called at. /// - function: **Do not provide a custom value.** The name of the declaration log method is called within. - public func log(_ object: Any, level: LogLevel = .default, file: String = #file, line: Int = #line, function: String = #function) { + public func log(_ object: Any, level: LogLevel, file: String = #file, line: Int = #line, function: String = #function) { let now = Date() let location = description(for: file, line: line, function: function) let objectDescription = description(for: object)