Skip to main content

Debug Mode

B2Metric provides various logging levels to help you debug event tracking during development.

Log Levels

enum LogLevel {
case off // No logs — recommended for production
case error // Only critical errors
case warning // Errors and warnings
case info // General information about SDK operations
case debug // Detailed information for debugging
}
LevelShows
.offNothing — all logs suppressed
.errorCritical failures that prevent SDK from working
.warningIssues that might cause problems
.infoSDK initialization, events sent, batch operations
.debugDetailed flow, every event logged, configuration details

Enable Debug Logging

Set the log level before starting the SDK:

B2MetricAnalytics.shared.logLevel = .debug
B2MetricAnalytics.shared.start(
apiKey: "YOUR_API_KEY",
batchSize: 20,
flushInterval: 30
)

Development vs Production Setup

#if DEBUG
// Verbose logging during development
B2MetricAnalytics.shared.logLevel = .debug
B2MetricAnalytics.shared.start(
apiKey: "DEV_API_KEY",
batchSize: 1, // Send immediately
flushInterval: 5
)
#else
// Minimal logging in production
B2MetricAnalytics.shared.logLevel = .error
B2MetricAnalytics.shared.start(
apiKey: "PROD_API_KEY",
batchSize: 50,
flushInterval: 60
)
#endif