-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathLogger+Ext.swift
More file actions
69 lines (56 loc) · 1.88 KB
/
Copy pathLogger+Ext.swift
File metadata and controls
69 lines (56 loc) · 1.88 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// Logger+Ext.swift
// klaviyo-swift-sdk
//
// Created by Andrew Balmer on 7/25/25.
//
import Foundation
import OSLog
// MARK: - Logging Configuration
/// Thread-safe global logging toggle for the Klaviyo SDK.
///
/// When logging is disabled, all `Logger` instances across every module
/// return `Logger(OSLog.disabled)`, which the OS optimises to a no-op.
package final class KlaviyoLogConfig: @unchecked Sendable {
package static let shared = KlaviyoLogConfig()
private let lock = NSLock()
private var _isLoggingEnabled: Bool = true
private init() {}
/// Whether logging is currently enabled across all Klaviyo SDK modules.
package var isLoggingEnabled: Bool {
get {
lock.lock()
defer { lock.unlock() }
return _isLoggingEnabled
}
set {
lock.lock()
defer { lock.unlock() }
_isLoggingEnabled = newValue
}
}
}
// MARK: - Logger Convenience Initializers
@available(iOS 14.0, *)
extension Logger {
private static var subsystem = "com.klaviyo.klaviyo-swift-sdk.klaviyoCore"
init(category: String) {
self.init(subsystem: Self.subsystem, category: category)
}
}
// MARK: - Loggers
@available(iOS 14.0, *)
extension Logger {
/// Logger for ``Codable`` events (JSON encoding & decoding)
static var codable: Logger {
KlaviyoLogConfig.shared.isLoggingEnabled ? Logger(category: "Encoding/Decoding Logger") : Logger(OSLog.disabled)
}
/// Logger for networking events
static var networking: Logger {
KlaviyoLogConfig.shared.isLoggingEnabled ? Logger(category: "Networking") : Logger(OSLog.disabled)
}
/// Logger for app navigation and deep linking events
static var navigation: Logger {
KlaviyoLogConfig.shared.isLoggingEnabled ? Logger(category: "Linking and Navigation") : Logger(OSLog.disabled)
}
}