null-safety: migrate super_logging using dart migrate

This commit is contained in:
Neeraj Gupta 2021-10-31 13:34:39 +05:30
parent 71eb662270
commit 8ae9d7180e
3 changed files with 24 additions and 31 deletions

View file

@ -248,13 +248,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
expansion_card:
dependency: "direct main"
description:
name: expansion_card
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
expansion_tile_card:
dependency: "direct main"
description:

View file

@ -33,7 +33,7 @@ extension SuperString on String {
}
extension SuperLogRecord on LogRecord {
String toPrettyString([String extraLines]) {
String toPrettyString([String? extraLines]) {
var header = "[$loggerName] [$level] [$time]";
var msg = "$header $message";
@ -71,7 +71,7 @@ class LogConfig {
/// ```
///
/// If this is [null], Sentry logger is completely disabled (default).
String sentryDsn;
String? sentryDsn;
/// A built-in retry mechanism for sending errors to sentry.
///
@ -88,7 +88,7 @@ class LogConfig {
/// A non-empty string will be treated as an explicit path to a directory.
///
/// The chosen directory can be accessed using [SuperLogging.logFile.parent].
String logDirPath;
String? logDirPath;
/// The maximum number of log files inside [logDirPath].
///
@ -106,12 +106,12 @@ class LogConfig {
/// any uncaught errors during its execution will be reported.
///
/// Works by using [FlutterError.onError] and [runZoned].
FutureOrVoidCallback body;
FutureOrVoidCallback? body;
/// The date format for storing log files.
///
/// `DateFormat('y-M-d')` by default.
DateFormat dateFmt;
DateFormat? dateFmt;
String prefix;
@ -134,9 +134,9 @@ class SuperLogging {
static final $ = Logger('ente_logging');
/// The current super logging configuration
static LogConfig config;
static late LogConfig config;
static Future<void> main([LogConfig config]) async {
static Future<void> main([LogConfig? config]) async {
config ??= LogConfig();
SuperLogging.config = config;
@ -173,12 +173,12 @@ class SuperLogging {
if (enable) {
await SentryFlutter.init(
(options) {
options.dsn = config.sentryDsn;
options.dsn = config!.sentryDsn;
},
appRunner: () => config.body(),
appRunner: () => config!.body!(),
);
} else {
await config.body();
await config.body!();
}
}
@ -187,7 +187,7 @@ class SuperLogging {
$.info("setting sentry user ID to: $userID");
}
static Future<void> _sendErrorToSentry(Object error, StackTrace stack) async {
static Future<void> _sendErrorToSentry(Object? error, StackTrace? stack) async {
try {
await Sentry.captureException(
error,
@ -199,11 +199,11 @@ class SuperLogging {
}
}
static var _lastExtraLines = '';
static String? _lastExtraLines = '';
static Future onLogRecord(LogRecord rec) async {
// log misc info if it changed
var extraLines = "app version: '$appVersion'\n";
String? extraLines = "app version: '$appVersion'\n";
if (extraLines != _lastExtraLines) {
_lastExtraLines = extraLines;
} else {
@ -257,7 +257,7 @@ class SuperLogging {
static final sentryQueueControl = StreamController<Error>();
/// Whether sentry logging is currently enabled or not.
static bool sentryIsEnabled;
static late bool sentryIsEnabled;
static Future<void> setupSentry() async {
await for (final error in sentryQueueControl.stream) {
@ -280,17 +280,17 @@ class SuperLogging {
}
/// The log file currently in use.
static File logFile;
static late File logFile;
/// Whether file logging is currently enabled or not.
static bool fileIsEnabled;
static late bool fileIsEnabled;
static Future<void> setupLogDir() async {
var dirPath = config.logDirPath;
var dirPath = config.logDirPath!;
// choose [logDir]
if (dirPath.isEmpty) {
var root = await getExternalStorageDirectory();
var root = await (getExternalStorageDirectory() as FutureOr<Directory>);
dirPath = '${root.path}/logs';
}
@ -304,8 +304,8 @@ class SuperLogging {
// collect all log files with valid names
await for (final file in dir.list()) {
try {
var date = config.dateFmt.parse(basename(file.path));
dates[file] = date;
var date = config.dateFmt!.parse(basename(file.path));
dates[file as File] = date;
files.add(file);
} on FormatException {}
}
@ -313,7 +313,7 @@ class SuperLogging {
// delete old log files, if [maxLogFiles] is exceeded.
if (files.length > config.maxLogFiles) {
// sort files based on ascending order of date (older first)
files.sort((a, b) => dates[a].compareTo(dates[b]));
files.sort((a, b) => dates[a]!.compareTo(dates[b]!));
var extra = files.length - config.maxLogFiles;
var toDelete = files.sublist(0, extra);
@ -325,13 +325,13 @@ class SuperLogging {
}
}
logFile = File("$dirPath/${config.dateFmt.format(DateTime.now())}.txt");
logFile = File("$dirPath/${config.dateFmt!.format(DateTime.now())}.txt");
}
/// Current app version, obtained from package_info plugin.
///
/// See: [getAppVersion]
static String appVersion;
static String? appVersion;
static Future<String> getAppVersion() async {
var pkgInfo = await PackageInfo.fromPlatform();

View file

@ -5,7 +5,7 @@ author: Dev Aggarwal <devpxy@gmail.com>
homepage: https://github.com/scientifichackers/super_logging
environment:
sdk: ">=2.6.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'
dependencies:
flutter: