mirror of
https://github.com/wnagrodzki/SwiftLogger.git
synced 2025-04-07 04:51:52 +02:00
Converted LogLevel to Int based enum
This commit is contained in:
parent
1803e1dc58
commit
e6f5138523
3 changed files with 21 additions and 8 deletions
|
@ -58,22 +58,35 @@ public protocol Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Log level controls the conditions under which a message should be logged.
|
/// Log level controls the conditions under which a message should be logged.
|
||||||
public enum LogLevel: String {
|
public enum LogLevel: Int {
|
||||||
|
|
||||||
/// Use this level to capture information about things that might result a failure.
|
/// Use this level to capture information about things that might result a failure.
|
||||||
case `default` = "Default"
|
case `default`
|
||||||
|
|
||||||
/// Use this level to capture information that may be helpful, but isn’t essential, for troubleshooting errors.
|
/// Use this level to capture information that may be helpful, but isn’t essential, for troubleshooting errors.
|
||||||
case info = "Info"
|
case info
|
||||||
|
|
||||||
/// Use this level to capture information that may be useful during development or while troubleshooting a specific problem.
|
/// Use this level to capture information that may be useful during development or while troubleshooting a specific problem.
|
||||||
case debug = "Debug"
|
case debug
|
||||||
|
|
||||||
/// Use this log level to capture process-level information to report errors in the process.
|
/// Use this log level to capture process-level information to report errors in the process.
|
||||||
case error = "Error"
|
case error
|
||||||
|
|
||||||
/// Use this level to capture system-level or multi-process information to report system errors.
|
/// Use this level to capture system-level or multi-process information to report system errors.
|
||||||
case fault = "Fault"
|
case fault
|
||||||
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Logger {
|
extension Logger {
|
||||||
|
|
|
@ -36,6 +36,6 @@ public final class ConsoleLogger: Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func log(time: Date, level: LogLevel, location: String, object: String) {
|
public func log(time: Date, level: LogLevel, location: String, object: String) {
|
||||||
print(formatter.string(from: time) + " <" + level.rawValue + "> " + location + " " + object)
|
print(formatter.string(from: time) + " <" + level.logDescription + "> " + location + " " + object)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ public final class DiskLogger: Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func log(time: Date, level: LogLevel, location: String, object: String) {
|
public func log(time: Date, level: LogLevel, location: String, object: String) {
|
||||||
let message = formatter.string(from: time) + " <" + level.rawValue + "> " + location + " " + object + "\n"
|
let message = formatter.string(from: time) + " <" + level.logDescription + "> " + location + " " + object + "\n"
|
||||||
log(message)
|
log(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue