Skip to content

Commit a5ae622

Browse files
authored
Support environment based log config in the demo app (#1062)
1 parent da5d79a commit a5ae622

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

DemoAppSwiftUI/AppDelegate.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ class AppDelegate: NSObject, UIApplicationDelegate {
6161
}
6262
#endif
6363

64+
LogConfig.level = StreamRuntimeCheck.logLevel ?? .warning
65+
LogConfig.formatters = [
66+
PrefixLogFormatter(prefixes: [.info: "ℹ️", .debug: "🛠", .warning: "⚠️", .error: "🚨"])
67+
]
68+
if let subsystems = StreamRuntimeCheck.subsystems {
69+
LogConfig.subsystems = subsystems
70+
}
71+
6472
let utils = Utils(
6573
channelListConfig: ChannelListConfig(
6674
messageRelativeDateFormatEnabled: true,
@@ -142,3 +150,17 @@ class AppDelegate: NSObject, UIApplicationDelegate {
142150
extension UIColor {
143151
static let streamBlue = UIColor(red: 0, green: 108.0 / 255.0, blue: 255.0 / 255.0, alpha: 1)
144152
}
153+
154+
extension StreamRuntimeCheck {
155+
static var logLevel: LogLevel? {
156+
guard let value = ProcessInfo.processInfo.environment["STREAM_LOG_LEVEL"] else { return nil }
157+
guard let intValue = Int(value) else { return nil }
158+
return LogLevel(rawValue: intValue)
159+
}
160+
161+
static var subsystems: LogSubsystem? {
162+
guard let value = ProcessInfo.processInfo.environment["STREAM_LOG_SUBSYSTEM"] else { return nil }
163+
guard let intValue = Int(value) else { return nil }
164+
return LogSubsystem(rawValue: intValue)
165+
}
166+
}

DemoAppSwiftUI/LoginViewModel.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class LoginViewModel: ObservableObject {
2525
private func connectUser(withCredentials credentials: UserCredentials) {
2626
loading = true
2727
let token = try! Token(rawValue: credentials.token)
28-
LogConfig.level = .warning
2928

3029
chatClient.connectUser(
3130
userInfo: .init(
@@ -53,7 +52,6 @@ class LoginViewModel: ObservableObject {
5352

5453
private func connectGuestUser(withCredentials credentials: UserCredentials) {
5554
loading = true
56-
LogConfig.level = .warning
5755

5856
chatClient.connectGuestUser(
5957
userInfo: .init(id: credentials.id, name: credentials.name)

0 commit comments

Comments
 (0)