Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced print in production with developer log #537

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ analyzer:
# Ignore generated files
- '**/*.g.dart'
- 'lib/src/generated/*.dart'

errors:
avoid_print: ignore

linter:
rules:
Expand Down
5 changes: 3 additions & 2 deletions packages/android_alarm_manager_plus/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'dart:ui';
import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/material.dart';
import 'dart:developer' as developer;

/// The [SharedPreferences] key to access the alarm fire count.
const String countKey = 'count';
Expand Down Expand Up @@ -78,7 +79,7 @@ class _AlarmHomePageState extends State<_AlarmHomePage> {
}

Future<void> _incrementCounter() async {
print('Increment counter!');
developer.log('Increment counter!');

// Ensure we've loaded the updated count from the background isolate.
await prefs.reload();
Expand All @@ -93,7 +94,7 @@ class _AlarmHomePageState extends State<_AlarmHomePage> {

// The callback for our alarm
static Future<void> callback() async {
print('Alarm fired!');
developer.log('Alarm fired!');

// Get the previous cached count and increment it.
final prefs = await SharedPreferences.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:developer' as developer;

const String _backgroundName =
'dev.fluttercommunity.plus/android_alarm_manager_background';
Expand All @@ -33,7 +34,7 @@ void _alarmManagerCallbackDispatcher() {
final closure = PluginUtilities.getCallbackFromHandle(handle);

if (closure == null) {
print('Fatal: could not find callback');
developer.log('Fatal: could not find callback');
exit(-1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import 'package:battery_plus/battery_plus.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'dart:developer' as developer;

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
Expand All @@ -21,7 +22,7 @@ void main() {
(WidgetTester tester) async {
final battery = Battery();
final isInBatterySaveMode = await battery.isInBatterySaveMode;
print(isInBatterySaveMode);
developer.log(isInBatterySaveMode.toString());
expect(isInBatterySaveMode, isNotNull);
});
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// ignore: import_of_legacy_library_into_null_safe
import 'package:dbus/dbus.dart';
import 'dart:developer' as developer;

const _kInterface = 'org.freedesktop.UPower';
const _kDeviceAddress = 'org.freedesktop.UPower.Device';
Expand Down Expand Up @@ -42,14 +43,14 @@ class UPowerDevice extends DBusRemoteObject {
Future<double> getPercentage() {
return getProperty(_kDeviceAddress, 'Percentage').then(
(value) => (value as DBusDouble).value,
onError: (error) => print(error),
onError: (error) => developer.log(error),
);
}

Future<UPowerBatteryState> getState() {
return getProperty(_kDeviceAddress, 'State').then(
(value) => (value as DBusUint32).value.toBatteryState(),
onError: (error) => print(error),
onError: (error) => developer.log(error),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:developer' as developer;

void main() {
runApp(const MyApp());
Expand Down Expand Up @@ -67,7 +68,7 @@ class _MyHomePageState extends State<MyHomePage> {
try {
result = await _connectivity.checkConnectivity();
} on PlatformException catch (e) {
print(e.toString());
developer.log(e.toString());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'dart:developer' as developer;

void main() {
runZonedGuarded(() {
runApp(const MyApp());
}, (dynamic error, dynamic stack) {
print(error);
print(stack);
developer.log(error);
developer.log(stack);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:network_info_plus/network_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:developer' as developer;

// Sets a platform override for desktop to avoid exceptions. See
// https://flutter.dev/desktop#target-platform-override for more info.
Expand Down Expand Up @@ -95,7 +96,7 @@ class _MyHomePageState extends State<MyHomePage> {
wifiName = await _networkInfo.getWifiName();
}
} on PlatformException catch (e) {
print(e.toString());
developer.log(e.toString());
wifiName = 'Failed to get Wifi Name';
}

Expand All @@ -115,49 +116,49 @@ class _MyHomePageState extends State<MyHomePage> {
wifiBSSID = await _networkInfo.getWifiBSSID();
}
} on PlatformException catch (e) {
print(e.toString());
developer.log(e.toString());
wifiBSSID = 'Failed to get Wifi BSSID';
}

try {
wifiIPv4 = await _networkInfo.getWifiIP();
} on PlatformException catch (e) {
print(e.toString());
developer.log(e.toString());
wifiIPv4 = 'Failed to get Wifi IPv4';
}

try {
wifiIPv6 = await _networkInfo.getWifiIPv6();
} on PlatformException catch (e) {
print(e.toString());
developer.log(e.toString());
wifiIPv6 = 'Failed to get Wifi IPv6';
}

try {
wifiSubmask = await _networkInfo.getWifiSubmask();
} on PlatformException catch (e) {
print(e.toString());
developer.log(e.toString());
wifiSubmask = 'Failed to get Wifi submask address';
}

try {
wifiBroadcast = await _networkInfo.getWifiBroadcast();
} on PlatformException catch (e) {
print(e.toString());
developer.log(e.toString());
wifiBroadcast = 'Failed to get Wifi broadcast';
}

try {
wifiGatewayIP = await _networkInfo.getWifiGatewayIP();
} on PlatformException catch (e) {
print(e.toString());
developer.log(e.toString());
wifiGatewayIP = 'Failed to get Wifi gateway address';
}

try {
wifiSubmask = await _networkInfo.getWifiSubmask();
} on PlatformException catch (e) {
print(e.toString());
developer.log(e.toString());
wifiSubmask = 'Failed to get Wifi submask';
}

Expand Down
18 changes: 11 additions & 7 deletions packages/sensors_plus/sensors_plus_web/lib/src/sensors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:js';
import 'dart:js_util';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:sensors_plus_platform_interface/sensors_plus_platform_interface.dart';
import 'dart:developer' as developer;

/// The sensors plugin.
class SensorsPlugin extends SensorsPlatform {
Expand Down Expand Up @@ -35,11 +36,11 @@ class SensorsPlugin extends SensorsPlatform {
/// See Feature-Policy for implementation instructions in the browsers.
if (error.toString().contains('SecurityError')) {
/// See the note above about feature policy.
print('$apiName construction was blocked by a feature policy.');
developer.log('$apiName construction was blocked by a feature policy.');

/// if this feature is not supported or Flag is not enabled yet!
} else if (error.toString().contains('ReferenceError')) {
print('$apiName is not supported by the User Agent.');
developer.log('$apiName is not supported by the User Agent.');

/// if this is unknown error, rethrow it
} else {
Expand Down Expand Up @@ -78,7 +79,8 @@ class SensorsPlugin extends SensorsPlatform {
_accelerometer.start();

_accelerometer.onError.forEach(
(e) => print('The Api is supported but something is wrong! $e'),
(e) => developer
.log('The Api is supported but something is wrong! $e'),
);
},
apiName: 'Accelerometer()',
Expand Down Expand Up @@ -124,7 +126,8 @@ class SensorsPlugin extends SensorsPlatform {
_gyroscope.start();

_gyroscope.onError.forEach(
(e) => print('The Api is supported but something is wrong! $e'),
(e) => developer
.log('The Api is supported but something is wrong! $e'),
);
},
apiName: 'Gyroscope()',
Expand Down Expand Up @@ -171,7 +174,8 @@ class SensorsPlugin extends SensorsPlatform {
_linearAccelerationSensor.start();

_linearAccelerationSensor.onError.forEach(
(e) => print('The Api is supported but something is wrong! $e'),
(e) => developer
.log('The Api is supported but something is wrong! $e'),
);
},
apiName: 'LinearAccelerationSensor()',
Expand Down Expand Up @@ -218,8 +222,8 @@ class SensorsPlugin extends SensorsPlatform {
_magnetometerSensor.start();

_magnetometerSensor.onError.forEach(
(e) =>
print('[SensorsPlugin] API supported but something is wrong: '
(e) => developer
.log('[SensorsPlugin] API supported but something is wrong: '
'Magnetometer $e'),
);
},
Expand Down
9 changes: 5 additions & 4 deletions packages/sensors_plus/sensors_plus_web/lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:html' as html;
import 'dart:developer' as developer;

/// Receive permission status of the API.
Future<void> checkPremission(
Expand All @@ -20,21 +21,21 @@ Future<void> checkPremission(
initSensor();
} else if (premissionStatus.state == 'prompt') {
/// user needs to intract with this
print(
developer.log(
'Premission [$premissionName] still has not been granted or denied.',
);
} else {
// If permission is denied, do not do anything
print('Permission [$premissionName] to use sensor was denied.');
developer.log('Permission [$premissionName] to use sensor was denied.');
}
} catch (e) {
print(
developer.log(
'Integration with Permissions API is not enabled, still try to start app.',
);
initSensor();
}
} else {
print('No Permissions API, still try to start app.');
developer.log('No Permissions API, still try to start app.');
initSensor();
}
}