Logging Configuration
Better Player provides an extensible logging system centered around the PlayerLogger. It supports native-to-Dart log streaming from Android (ExoPlayer), iOS and macOS (AVPlayer), and Windows (libmpv), automatic caller derivation, and custom output backends.
Setup
The logging system is configured via PlayerLoggerConfiguration, which is passed to your PlayerConfiguration:
import 'package:better_player/better_player.dart';
var playerConfiguration = PlayerConfiguration(
playerLogConfiguration: PlayerLoggerConfiguration(
logLevel: PlayerLogLevel.debug,
printCallerInfo: true,
outputs: [ConsoleLogOutput()],
),
);
By default, Better Player uses PlayerLoggerConfiguration.defaultConfig, which sets the level to debug in debug mode and info in profile or release builds.
Configuration Parameters
logLevel: The minimum level required for a record to be sent to outputs. UsePlayerLogLevel.noneto disable all logging.printCallerInfo: Iftrue, the logger will automatically parse the stack trace to include the class and method name that triggered the log. (Default:true).outputs: A list ofPlayerLogOutputinstances. Defaults to[ConsoleLogOutput()], which usesdart:developerfor IDE and DevTools integration.
Log Levels
Better Player uses the following hierarchy (from lowest to highest):
PlayerLogLevel.debug: Fine-grained informational events that are most useful to debug an application.PlayerLogLevel.info: Informational messages that highlight the progress of the application at coarse-grained level.PlayerLogLevel.warning: Potentially harmful situations.PlayerLogLevel.error: Error events that might still allow the application to continue running.PlayerLogLevel.none: Special level used to turn off logging.
Native Log Streaming
Better Player automatically captures logs from the native playback engines:
- Android: Internal events from ExoPlayer's
Player.Listenerand lifecycle logs. - iOS & macOS: State changes via KVO (Key-Value Observing) on
AVPlayerand native lifecycle logs. - Windows: Internal events and diagnostics from
libmpvand Direct3D 11 texture lifecycle.
These logs are forwarded to Dart and routed through PlayerLogger with the Android, iOS, macOS, or Windows tag, allowing you to see exactly what is happening in the native layer within your Flutter console or custom log backends.
Custom Log Outputs
To send logs to external services like Sentry, Firebase Crashlytics, or a local file, extend the PlayerLogOutput class:
class CustomCrashlyticsOutput extends PlayerLogOutput {
void onLog(PlayerLogRecord record) {
if (record.level == PlayerLogLevel.error) {
// Example: Crashlytics.instance.recordError(record.error, record.stackTrace);
}
}
}
PlayerLogRecord Fields
Every log entry is encapsulated in a PlayerLogRecord containing:
level: ThePlayerLogLevel.message: The formatted log message.tag: The category (e.g.,BetterPlayerController,Android, or a custom tag).timestamp: UTCDateTimewhen the log was created.caller: The derived calling method (ifprintCallerInfois enabled).error: Optional error object.stackTrace: Optional stack trace.