import StreamChat
LogConfig.level = .debugLogs
Enable Logging
By default, logging is disabled. You can enable the logs by setting the log level in the LogConfig. It is recommended to enable the logs in development builds only and as soon as you create the ChatClient.
Log Levels
There are four different level’s available.
.debug: It will log everything for debugging purposes..info: It will log additional information besides warnings and errors..warning: It will log warnings and errors..error: It will only log errors.
Log Subsystems
In case you are debugging a specific area of the SDK, you can filter the logs based on subsystems. You can select one or multiple subsystems:
import StreamChat
// Only one subsystem
LogConfig.subsystems = .httpRequests
// Multiple subsystems
LogConfig.subsystems = [.httpRequests, .authentication]There are the following subsystems available.
.all: The default, this will log all subsystems..database: The subsystem responsible for database operations..httpRequests: The subsystem responsible for HTTP operations..webSocket: The subsystem responsible for WebSocket operations..offlineSupport: The subsystem responsible for offline support..authentication: The subsystem responsible for authentication..audioPlayback: The subsystem responsible for audio playback..audioRecording: The subsystem responsible for audio recording..other: The subsystem related to misc logs and not related to any subsystem.
Debugging
When debugging an issue, we recommend to start by logging the HTTP requests and the WebSocket events, and only set more specific subsystems if required, or if you want to only debug a specific area.
LogConfig.level = .debug
LogConfig.subsystems = [.httpRequests, .webSocket]If you want, you can also only debug the HTTP requests by setting the subsystems to only .httpRequests, or only the WebSocket events by setting the subsystems to only .webSocket.
Customizing Logs
By default, logs are output as plain text to your console. However, the SDK also provides functionality to customize log messages with emojis, making it easier to identify logs generated by the SDK.
LogConfig.formatters = [
PrefixLogFormatter(
prefixes: [
.info: "ℹ️",
.debug: "🛠",
.warning: "⚠️",
.error: "🚨"
]
)
]It’s also possible to hide certain parts of the log messages:
LogConfig.showThreadName = false
LogConfig.showDate = false
LogConfig.showFunctionName = falseIn the example above, the threadName, date and functionName are hidden from the logs.
Intercepting Logs
You can also intercept logs generated by the SDK and send them to your own servers or to any third-party analytics provider.
To do this, create a custom log destination:
class CustomLogDestination: BaseLogDestination {
override func process(logDetails: LogDetails) {
let level = logDetails.level
let message = logDetails.message
// Send the log details to your server or third-party SDK
...
}
}Make sure that you set the log destination before creating the ChatClient:
LogConfig.destinationTypes = [
ConsoleLogDestination.self,
CustomLogDestination.self // Your custom destination
]