1 |
//
|
|
2 |
// RouteComposer
|
|
3 |
// DefaultLogger.swift
|
|
4 |
// https://github.com/ekazaev/route-composer
|
|
5 |
//
|
|
6 |
// Created by Eugene Kazaev in 2018-2022.
|
|
7 |
// Distributed under the MIT license.
|
|
8 |
//
|
|
9 |
// Become a sponsor:
|
|
10 |
// https://github.com/sponsors/ekazaev
|
|
11 |
//
|
|
12 |
|
|
13 |
import Foundation
|
|
14 |
import os.log
|
|
15 |
|
|
16 |
/// Default Logger implementation
|
|
17 |
public struct DefaultLogger: Logger {
|
|
18 |
|
|
19 |
// MARK: Properties
|
|
20 |
|
|
21 |
/// Log level
|
|
22 |
public let logLevel: LogLevel
|
|
23 |
|
|
24 |
private let osLog: OSLog
|
|
25 |
|
|
26 |
// MARK: Methods
|
|
27 |
|
|
28 |
/// Constructor.
|
|
29 |
///
|
|
30 |
/// - Parameters:
|
|
31 |
/// - logLevel: DefaultLoggerLevel. Defaulted to warnings.
|
|
32 |
/// - osLog: OSLog instance of the app.
|
|
33 |
public init(_ logLevel: LogLevel = .warnings,
|
|
34 |
osLog: OSLog = OSLog.default) {
|
14x |
35 |
self.logLevel = logLevel
|
14x |
36 |
self.osLog = osLog
|
14x |
37 |
}
|
14x |
38 |
|
|
39 |
public func log(_ message: LogMessage) {
|
1180x |
40 |
switch message {
|
1180x |
41 |
case let .warning(message):
|
1180x |
42 |
if logLevel == .verbose || logLevel == .warnings {
|
! |
43 |
os_log("%@", log: osLog, type: .error, message)
|
! |
44 |
}
|
1180x |
45 |
case let .info(message):
|
1180x |
46 |
if logLevel == .verbose {
|
1160x |
47 |
os_log("%@", log: osLog, type: .info, message)
|
1160x |
48 |
}
|
1180x |
49 |
case let .error(message):
|
1180x |
50 |
os_log("%@", log: osLog, type: .fault, message)
|
16x |
51 |
}
|
1180x |
52 |
}
|
1180x |
53 |
|
|
54 |
}
|
|