-
Notifications
You must be signed in to change notification settings - Fork 199
/
LogLevel.swift
55 lines (51 loc) · 1.74 KB
/
LogLevel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
/// Log levels are modeled as Ints to allow for easy comparison of levels
///
public extension Amplify {
enum LogLevel: Int, Codable {
case none
case error
case warn
case info
case debug
case verbose
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let rawString = try? container.decode(String.self).lowercased() {
switch rawString {
case "error":
self = .error
case "warn":
self = .warn
case "info":
self = .info
case "debug":
self = .debug
case "verbose":
self = .verbose
case "none":
self = .none
default:
let context = DecodingError.Context(codingPath: [], debugDescription: "No matching LogLevel found")
throw DecodingError.valueNotFound(LogLevel.self, context)
}
} else if let rawInt = try? container.decode(Int.self), let value = LogLevel(rawValue: rawInt) {
self = value
} else {
let context = DecodingError.Context(codingPath: [], debugDescription: "Unable to decode LogLevel")
throw DecodingError.dataCorrupted(context)
}
}
}
}
public typealias LogLevel = Amplify.LogLevel
extension LogLevel: Comparable {
public static func < (lhs: LogLevel, rhs: LogLevel) -> Bool {
lhs.rawValue < rhs.rawValue
}
}