add log output on location error in background

This commit is contained in:
Yegor Vialov 2020-03-15 17:51:01 +00:00
parent 6ad3938a91
commit c40fceea4f

View File

@ -172,13 +172,13 @@ void updateDeviceLocationIsolate() {
"battery": 100 "battery": 100
} }
}; };
//print("[Background $backgroundTask] Getting battery level..."); print("[Background $backgroundTask] Getting battery level...");
int batteryLevel; int batteryLevel;
try { try {
batteryLevel = await battery.batteryLevel; batteryLevel = await battery.batteryLevel;
//print("[Background $backgroundTask] Got battery level: $batteryLevel"); print("[Background $backgroundTask] Got battery level: $batteryLevel");
} catch(e) { } catch(e) {
//print("[Background $backgroundTask] Error getting battery level: $e. Setting zero"); print("[Background $backgroundTask] Error getting battery level: $e. Setting zero");
batteryLevel = 0; batteryLevel = 0;
logData += 'Battery: error, $e'; logData += 'Battery: error, $e';
} }
@ -192,7 +192,6 @@ void updateDeviceLocationIsolate() {
try { try {
location = await geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high, locationPermissionLevel: GeolocationPermission.locationAlways); location = await geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high, locationPermissionLevel: GeolocationPermission.locationAlways);
if (location != null && location.latitude != null) { if (location != null && location.latitude != null) {
//print("[Background $backgroundTask] Got location: ${location.latitude} ${location.longitude} (${location.timestamp})");
logData += ' || Location: success, ${location.latitude} ${location.longitude} (${location.timestamp})'; logData += ' || Location: success, ${location.latitude} ${location.longitude} (${location.timestamp})';
data["data"]["gps"] = [location.latitude, location.longitude]; data["data"]["gps"] = [location.latitude, location.longitude];
data["data"]["gps_accuracy"] = location.accuracy; data["data"]["gps_accuracy"] = location.accuracy;
@ -214,9 +213,9 @@ void updateDeviceLocationIsolate() {
logData += ' || Location: error, location is null'; logData += ' || Location: error, location is null';
} }
} catch (e) { } catch (e) {
print("[Background $backgroundTask] Location error: $e");
logData += ' || Location: error, $e'; logData += ' || Location: error, $e';
} }
//print("[Background $backgroundTask] Sending data home.");
} else { } else {
logData += 'Not configured'; logData += 'Not configured';
} }