feat(logging): add logging to home voice recorder
This commit is contained in:
@@ -3,7 +3,8 @@ import 'dart:io';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:record/record.dart';
|
||||
|
||||
import '../../../core/l10n/l10n.dart';
|
||||
import '../../../../core/l10n/l10n.dart';
|
||||
import '../../../../core/logging/logger.dart';
|
||||
|
||||
abstract class VoiceRecorder {
|
||||
Future<void> start();
|
||||
@@ -13,6 +14,7 @@ abstract class VoiceRecorder {
|
||||
|
||||
class RecordVoiceRecorder implements VoiceRecorder {
|
||||
final AudioRecorder _recorder;
|
||||
final Logger _logger = getLogger('features.home.voice_recorder');
|
||||
String? _currentPath;
|
||||
|
||||
RecordVoiceRecorder({AudioRecorder? recorder})
|
||||
@@ -23,10 +25,16 @@ class RecordVoiceRecorder implements VoiceRecorder {
|
||||
bool hasPermission;
|
||||
try {
|
||||
hasPermission = await _recorder.hasPermission();
|
||||
} on MissingPluginException catch (_) {
|
||||
} on MissingPluginException catch (e, stackTrace) {
|
||||
_logger.error(
|
||||
message: 'Voice recorder plugin unavailable',
|
||||
error: e,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
throw StateError(L10n.current.homeRecorderPluginUnavailable);
|
||||
}
|
||||
if (!hasPermission) {
|
||||
_logger.warning(message: 'Voice recorder permission denied');
|
||||
throw StateError(L10n.current.homeRecorderPermissionDenied);
|
||||
}
|
||||
|
||||
@@ -43,7 +51,13 @@ class RecordVoiceRecorder implements VoiceRecorder {
|
||||
),
|
||||
path: path,
|
||||
);
|
||||
} on MissingPluginException catch (_) {
|
||||
_logger.info(message: 'Voice recording started', extra: {'path': path});
|
||||
} on MissingPluginException catch (e, stackTrace) {
|
||||
_logger.error(
|
||||
message: 'Failed to start voice recording',
|
||||
error: e,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
throw StateError(L10n.current.homeRecorderPluginUnavailable);
|
||||
}
|
||||
}
|
||||
@@ -53,7 +67,16 @@ class RecordVoiceRecorder implements VoiceRecorder {
|
||||
String? stoppedPath;
|
||||
try {
|
||||
stoppedPath = await _recorder.stop();
|
||||
} on MissingPluginException catch (_) {
|
||||
_logger.info(
|
||||
message: 'Voice recording stopped',
|
||||
extra: {'path': stoppedPath ?? _currentPath},
|
||||
);
|
||||
} on MissingPluginException catch (e, stackTrace) {
|
||||
_logger.error(
|
||||
message: 'Failed to stop voice recording',
|
||||
error: e,
|
||||
stackTrace: stackTrace,
|
||||
);
|
||||
throw StateError(L10n.current.homeRecorderPluginUnavailable);
|
||||
}
|
||||
return stoppedPath ?? _currentPath;
|
||||
|
||||
Reference in New Issue
Block a user