mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
feat: improve and unify the logging framework (#738)
* Improve logging framework for better debugging Signed-off-by: meenbeese <meenbeese@tutanota.com> * Remove logger statements from /bin dir --------- Signed-off-by: meenbeese <meenbeese@tutanota.com>
This commit is contained in:
parent
fe42cfe843
commit
c7432bbd98
@ -68,6 +68,7 @@ void main() async {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ignore: avoid_print
|
||||||
print(
|
print(
|
||||||
packageInfo
|
packageInfo
|
||||||
.map(
|
.map(
|
||||||
@ -76,6 +77,7 @@ void main() async {
|
|||||||
)
|
)
|
||||||
.join('\n'),
|
.join('\n'),
|
||||||
);
|
);
|
||||||
|
// ignore: avoid_print
|
||||||
print(
|
print(
|
||||||
gitPubspecs.map(
|
gitPubspecs.map(
|
||||||
(package) {
|
(package) {
|
||||||
|
@ -35,6 +35,7 @@ void main(List<String> args) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ignore: avoid_print
|
||||||
print(
|
print(
|
||||||
const JsonEncoder.withIndent(' ').convert(
|
const JsonEncoder.withIndent(' ').convert(
|
||||||
args.isNotEmpty ? messagesWithValues[args.first] : messagesWithValues,
|
args.isNotEmpty ? messagesWithValues[args.first] : messagesWithValues,
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
import 'package:spotube/models/logger.dart';
|
||||||
|
|
||||||
|
final logger = getLogger("List");
|
||||||
|
|
||||||
extension MultiSortListMap on List<Map> {
|
extension MultiSortListMap on List<Map> {
|
||||||
/// [preference] - List of properties in which you want to sort the list
|
/// [preference] - List of properties in which you want to sort the list
|
||||||
@ -18,7 +21,7 @@ extension MultiSortListMap on List<Map> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if (preference.length != criteria.length) {
|
if (preference.length != criteria.length) {
|
||||||
print('Criteria length is not equal to preference');
|
logger.d('Criteria length is not equal to preference');
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +69,7 @@ extension MultiSortListTupleMap<V> on List<(Map, V)> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if (preference.length != criteria.length) {
|
if (preference.length != criteria.length) {
|
||||||
print('Criteria length is not equal to preference');
|
logger.d('Criteria length is not equal to preference');
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,8 @@ class SpotubeLogger extends Logger {
|
|||||||
SpotubeLogger([this.owner]) : super(filter: _SpotubeLogFilter());
|
SpotubeLogger([this.owner]) : super(filter: _SpotubeLogFilter());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void log(Level level, message, [error, StackTrace? stackTrace]) async {
|
void log(Level level, dynamic message,
|
||||||
|
{Object? error, StackTrace? stackTrace, DateTime? time}) async {
|
||||||
if (!kIsWeb) {
|
if (!kIsWeb) {
|
||||||
if (level == Level.error) {
|
if (level == Level.error) {
|
||||||
String dir = (await getApplicationDocumentsDirectory()).path;
|
String dir = (await getApplicationDocumentsDirectory()).path;
|
||||||
@ -56,7 +57,7 @@ class SpotubeLogger extends Logger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
super.log(level, "[$owner] $message", error, stackTrace);
|
super.log(level, "[$owner] $message", error: error, stackTrace: stackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ class _SpotubeLogFilter extends DevelopmentFilter {
|
|||||||
@override
|
@override
|
||||||
bool shouldLog(LogEvent event) {
|
bool shouldLog(LogEvent event) {
|
||||||
if ((logEnv["DEBUG"] == "true" && event.level == Level.debug) ||
|
if ((logEnv["DEBUG"] == "true" && event.level == Level.debug) ||
|
||||||
(logEnv["VERBOSE"] == "true" && event.level == Level.verbose) ||
|
(logEnv["VERBOSE"] == "true" && event.level == Level.trace) ||
|
||||||
(logEnv["ERROR"] == "true" && event.level == Level.error)) {
|
(logEnv["ERROR"] == "true" && event.level == Level.error)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:spotify/spotify.dart';
|
import 'package:spotify/spotify.dart';
|
||||||
import 'package:spotube/models/local_track.dart';
|
import 'package:spotube/models/local_track.dart';
|
||||||
|
import 'package:spotube/models/logger.dart';
|
||||||
import 'package:spotube/models/matched_track.dart';
|
import 'package:spotube/models/matched_track.dart';
|
||||||
import 'package:spotube/models/spotube_track.dart';
|
import 'package:spotube/models/spotube_track.dart';
|
||||||
import 'package:spotube/provider/proxy_playlist/proxy_playlist.dart';
|
import 'package:spotube/provider/proxy_playlist/proxy_playlist.dart';
|
||||||
@ -10,6 +11,8 @@ import 'package:spotube/provider/user_preferences_provider.dart';
|
|||||||
import 'package:spotube/services/supabase.dart';
|
import 'package:spotube/services/supabase.dart';
|
||||||
import 'package:spotube/services/youtube/youtube.dart';
|
import 'package:spotube/services/youtube/youtube.dart';
|
||||||
|
|
||||||
|
final logger = getLogger("NextFetcherMixin");
|
||||||
|
|
||||||
mixin NextFetcher on StateNotifier<ProxyPlaylist> {
|
mixin NextFetcher on StateNotifier<ProxyPlaylist> {
|
||||||
Future<List<SpotubeTrack>> fetchTracks(
|
Future<List<SpotubeTrack>> fetchTracks(
|
||||||
UserPreferences preferences,
|
UserPreferences preferences,
|
||||||
@ -124,8 +127,8 @@ mixin NextFetcher on StateNotifier<ProxyPlaylist> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
debugPrint(e.toString());
|
logger.e(e.toString());
|
||||||
debugPrintStack(stackTrace: stackTrace);
|
logger.t(stackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -591,7 +591,7 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
|||||||
end,
|
end,
|
||||||
);
|
);
|
||||||
}).toList();
|
}).toList();
|
||||||
getLogger('getSkipSegments').v(
|
getLogger('getSkipSegments').t(
|
||||||
"[SponsorBlock] successfully fetched skip segments for $id",
|
"[SponsorBlock] successfully fetched skip segments for $id",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3,6 +3,9 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:spotube/models/logger.dart';
|
||||||
|
|
||||||
|
final logger = getLogger("ChunkedDownload");
|
||||||
|
|
||||||
/// Downloading by spiting as file in chunks
|
/// Downloading by spiting as file in chunks
|
||||||
extension ChunkDownload on Dio {
|
extension ChunkDownload on Dio {
|
||||||
@ -67,11 +70,11 @@ extension ChunkDownload on Dio {
|
|||||||
}
|
}
|
||||||
await raf.close();
|
await raf.close();
|
||||||
|
|
||||||
debugPrint("Downloaded file path: ${headFile.path}");
|
logger.d("Downloaded file path: ${headFile.path}");
|
||||||
|
|
||||||
headFile = await headFile.rename(savePath);
|
headFile = await headFile.rename(savePath);
|
||||||
|
|
||||||
debugPrint("Renamed file path: ${headFile.path}");
|
logger.d("Renamed file path: ${headFile.path}");
|
||||||
}
|
}
|
||||||
|
|
||||||
final firstResponse = await downloadChunk(
|
final firstResponse = await downloadChunk(
|
||||||
|
@ -6,6 +6,7 @@ import 'package:collection/collection.dart';
|
|||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:spotube/models/logger.dart';
|
||||||
import 'package:spotube/services/download_manager/chunked_download.dart';
|
import 'package:spotube/services/download_manager/chunked_download.dart';
|
||||||
import 'package:spotube/services/download_manager/download_request.dart';
|
import 'package:spotube/services/download_manager/download_request.dart';
|
||||||
import 'package:spotube/services/download_manager/download_status.dart';
|
import 'package:spotube/services/download_manager/download_status.dart';
|
||||||
@ -22,6 +23,7 @@ typedef DownloadStatusEvent = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
class DownloadManager {
|
class DownloadManager {
|
||||||
|
final logger = getLogger("DownloadManager");
|
||||||
final Map<String, DownloadTask> _cache = <String, DownloadTask>{};
|
final Map<String, DownloadTask> _cache = <String, DownloadTask>{};
|
||||||
final Queue<DownloadRequest> _queue = Queue();
|
final Queue<DownloadRequest> _queue = Queue();
|
||||||
var dio = Dio();
|
var dio = Dio();
|
||||||
@ -73,7 +75,7 @@ class DownloadManager {
|
|||||||
}
|
}
|
||||||
setStatus(task, DownloadStatus.downloading);
|
setStatus(task, DownloadStatus.downloading);
|
||||||
|
|
||||||
debugPrint("[DownloadManager] $url");
|
logger.d("[DownloadManager] $url");
|
||||||
final file = File(savePath.toString());
|
final file = File(savePath.toString());
|
||||||
partialFilePath = savePath + partialExtension;
|
partialFilePath = savePath + partialExtension;
|
||||||
partialFile = File(partialFilePath);
|
partialFile = File(partialFilePath);
|
||||||
@ -82,10 +84,10 @@ class DownloadManager {
|
|||||||
final partialFileExist = await partialFile.exists();
|
final partialFileExist = await partialFile.exists();
|
||||||
|
|
||||||
if (fileExist) {
|
if (fileExist) {
|
||||||
debugPrint("[DownloadManager] File Exists");
|
logger.d("[DownloadManager] File Exists");
|
||||||
setStatus(task, DownloadStatus.completed);
|
setStatus(task, DownloadStatus.completed);
|
||||||
} else if (partialFileExist) {
|
} else if (partialFileExist) {
|
||||||
debugPrint("[DownloadManager] Partial File Exists");
|
logger.d("[DownloadManager] Partial File Exists");
|
||||||
|
|
||||||
final partialFileLength = await partialFile.length();
|
final partialFileLength = await partialFile.length();
|
||||||
|
|
||||||
@ -205,7 +207,7 @@ class DownloadManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> pauseDownload(String url) async {
|
Future<void> pauseDownload(String url) async {
|
||||||
debugPrint("[DownloadManager] Pause Download");
|
logger.d("[DownloadManager] Pause Download");
|
||||||
var task = getDownload(url)!;
|
var task = getDownload(url)!;
|
||||||
setStatus(task, DownloadStatus.paused);
|
setStatus(task, DownloadStatus.paused);
|
||||||
task.request.cancelToken.cancel();
|
task.request.cancelToken.cancel();
|
||||||
@ -214,7 +216,7 @@ class DownloadManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cancelDownload(String url) async {
|
Future<void> cancelDownload(String url) async {
|
||||||
debugPrint("[DownloadManager] Cancel Download");
|
logger.d("[DownloadManager] Cancel Download");
|
||||||
var task = getDownload(url)!;
|
var task = getDownload(url)!;
|
||||||
setStatus(task, DownloadStatus.canceled);
|
setStatus(task, DownloadStatus.canceled);
|
||||||
_queue.remove(task.request);
|
_queue.remove(task.request);
|
||||||
@ -222,7 +224,7 @@ class DownloadManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> resumeDownload(String url) async {
|
Future<void> resumeDownload(String url) async {
|
||||||
debugPrint("[DownloadManager] Resume Download");
|
logger.d("[DownloadManager] Resume Download");
|
||||||
var task = getDownload(url)!;
|
var task = getDownload(url)!;
|
||||||
setStatus(task, DownloadStatus.downloading);
|
setStatus(task, DownloadStatus.downloading);
|
||||||
task.request.cancelToken = CancelToken();
|
task.request.cancelToken = CancelToken();
|
||||||
@ -388,7 +390,7 @@ class DownloadManager {
|
|||||||
|
|
||||||
while (_queue.isNotEmpty && runningTasks < maxConcurrentTasks) {
|
while (_queue.isNotEmpty && runningTasks < maxConcurrentTasks) {
|
||||||
runningTasks++;
|
runningTasks++;
|
||||||
debugPrint('Concurrent workers: $runningTasks');
|
logger.d('Concurrent workers: $runningTasks');
|
||||||
var currentRequest = _queue.removeFirst();
|
var currentRequest = _queue.removeFirst();
|
||||||
|
|
||||||
await download(
|
await download(
|
||||||
|
@ -1226,10 +1226,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: logger
|
name: logger
|
||||||
sha256: "7ad7215c15420a102ec687bb320a7312afd449bac63bfb1c60d9787c27b9767f"
|
sha256: ba3bc83117b2b49bdd723c0ea7848e8285a0fbc597ba09203b20d329d020c24a
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.0"
|
version: "2.0.2"
|
||||||
logging:
|
logging:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -69,7 +69,7 @@ dependencies:
|
|||||||
intl: ^0.18.0
|
intl: ^0.18.0
|
||||||
introduction_screen: ^3.0.2
|
introduction_screen: ^3.0.2
|
||||||
json_annotation: ^4.8.1
|
json_annotation: ^4.8.1
|
||||||
logger: ^1.1.0
|
logger: ^2.0.2
|
||||||
media_kit: ^1.1.3
|
media_kit: ^1.1.3
|
||||||
media_kit_libs_audio: ^1.0.1
|
media_kit_libs_audio: ^1.0.1
|
||||||
metadata_god: ^0.5.0
|
metadata_god: ^0.5.0
|
||||||
|
Loading…
Reference in New Issue
Block a user