Logger
The Logger utility provides control over logging output from the Mapbox Maps SDK. You can set the log level and customize log handling with a custom callback.Import
Basic Usage
Methods
setLogLevel()
The minimum level of logging to display.Valid values:
'error'- Only errors'warning'- Errors and warnings'info'- Errors, warnings, and info messages'debug'- Errors, warnings, info, and debug messages'verbose'- All log messages
setLogCallback()
- Redirect logs to your own logging system
- Filter or modify log messages
- Suppress default logging
Callback function that receives log objects.Parameters:
log: LogObject - The log message object
boolean- Returntrueto suppress default logging,falseto allow it
Types
LogLevel
LogObject
LogCallback
true to suppress default logging.
Examples
- Basic Log Level
- Custom Logger
- Filter Messages
- Analytics Integration
- Debug Mode
Default Behavior
The Logger automatically:- Starts listening for log events on initialization
- Filters HTTP request cancellation warnings (common and usually not actionable)
- Formats logs with
[Mapbox level]prefix - Routes logs to appropriate console methods (
console.error,console.warn,console.log)
Best Practices
- Set Log Level Early: Configure logging as early as possible in your app’s lifecycle
- Environment-Based Levels: Use verbose logging in development, error-only in production
- Custom Callback for Production: Implement custom logging to send errors to monitoring services
- Filter Noise: Use the callback to suppress known non-critical warnings
- Performance: Avoid expensive operations in the log callback
Common Patterns
Production Error Tracking
Development Debugging
Mute Specific Warnings
Related
- MapView - The main map component
- Mapbox Module - Core module configuration