mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-16 00:09:23 +00:00

git-subtree-dir: submodules/TelegramCore git-subtree-mainline: 971273e8f8f49a47f14b251d2f35e3445a61fc3f git-subtree-split: 9561227540acef69894e6546395ab223a6233600
99 lines
3.6 KiB
Swift
99 lines
3.6 KiB
Swift
import Foundation
|
|
#if os(macOS)
|
|
import PostboxMac
|
|
import SwiftSignalKitMac
|
|
import MtProtoKitMac
|
|
#else
|
|
import Postbox
|
|
import SwiftSignalKit
|
|
#if BUCK
|
|
import MtProtoKit
|
|
#else
|
|
import MtProtoKitDynamic
|
|
#endif
|
|
#endif
|
|
|
|
public final class LoggingSettings: PreferencesEntry, Equatable {
|
|
public let logToFile: Bool
|
|
public let logToConsole: Bool
|
|
public let redactSensitiveData: Bool
|
|
|
|
#if DEBUG
|
|
public static var defaultSettings = LoggingSettings(logToFile: true, logToConsole: true, redactSensitiveData: true)
|
|
#else
|
|
public static var defaultSettings = LoggingSettings(logToFile: false, logToConsole: false, redactSensitiveData: true)
|
|
#endif
|
|
|
|
public init(logToFile: Bool, logToConsole: Bool, redactSensitiveData: Bool) {
|
|
self.logToFile = logToFile
|
|
self.logToConsole = logToConsole
|
|
self.redactSensitiveData = redactSensitiveData
|
|
}
|
|
|
|
public init(decoder: PostboxDecoder) {
|
|
self.logToFile = decoder.decodeInt32ForKey("logToFile", orElse: 0) != 0
|
|
self.logToConsole = decoder.decodeInt32ForKey("logToConsole", orElse: 0) != 0
|
|
self.redactSensitiveData = decoder.decodeInt32ForKey("redactSensitiveData", orElse: 1) != 0
|
|
}
|
|
|
|
public func encode(_ encoder: PostboxEncoder) {
|
|
encoder.encodeInt32(self.logToFile ? 1 : 0, forKey: "logToFile")
|
|
encoder.encodeInt32(self.logToConsole ? 1 : 0, forKey: "logToConsole")
|
|
encoder.encodeInt32(self.redactSensitiveData ? 1 : 0, forKey: "redactSensitiveData")
|
|
}
|
|
|
|
public func withUpdatedLogToFile(_ logToFile: Bool) -> LoggingSettings {
|
|
return LoggingSettings(logToFile: logToFile, logToConsole: self.logToConsole, redactSensitiveData: self.redactSensitiveData)
|
|
}
|
|
|
|
public func withUpdatedLogToConsole(_ logToConsole: Bool) -> LoggingSettings {
|
|
return LoggingSettings(logToFile: self.logToFile, logToConsole: logToConsole, redactSensitiveData: self.redactSensitiveData)
|
|
}
|
|
|
|
public func withUpdatedRedactSensitiveData(_ redactSensitiveData: Bool) -> LoggingSettings {
|
|
return LoggingSettings(logToFile: self.logToFile, logToConsole: self.logToConsole, redactSensitiveData: redactSensitiveData)
|
|
}
|
|
|
|
public static func ==(lhs: LoggingSettings, rhs: LoggingSettings) -> Bool {
|
|
if lhs.logToFile != rhs.logToFile {
|
|
return false
|
|
}
|
|
if lhs.logToConsole != rhs.logToConsole {
|
|
return false
|
|
}
|
|
if lhs.redactSensitiveData != rhs.redactSensitiveData {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
public func isEqual(to: PreferencesEntry) -> Bool {
|
|
guard let to = to as? LoggingSettings else {
|
|
return false
|
|
}
|
|
|
|
return self == to
|
|
}
|
|
}
|
|
|
|
public func updateLoggingSettings(accountManager: AccountManager, _ f: @escaping (LoggingSettings) -> LoggingSettings) -> Signal<Void, NoError> {
|
|
return accountManager.transaction { transaction -> Void in
|
|
var updated: LoggingSettings?
|
|
transaction.updateSharedData(SharedDataKeys.loggingSettings, { current in
|
|
if let current = current as? LoggingSettings {
|
|
updated = f(current)
|
|
return updated
|
|
} else {
|
|
updated = f(LoggingSettings.defaultSettings)
|
|
return updated
|
|
}
|
|
})
|
|
|
|
if let updated = updated {
|
|
Logger.shared.logToFile = updated.logToFile
|
|
Logger.shared.logToConsole = updated.logToConsole
|
|
Logger.shared.redactSensitiveData = updated.redactSensitiveData
|
|
}
|
|
}
|
|
}
|