diff --git a/lib/API/musify.dart b/lib/API/musify.dart index bb6d7898c..3d8770fc1 100644 --- a/lib/API/musify.dart +++ b/lib/API/musify.dart @@ -61,7 +61,7 @@ Future fetchSongsList(String searchQuery) async { return searchResults.map((video) => returnSongLayout(0, video)).toList(); } catch (e, stackTrace) { - logger.log('Error in fetchSongsList:$e\n$stackTrace'); + logger.log('Error in fetchSongsList', e, stackTrace); return []; } } @@ -92,7 +92,7 @@ Future getRecommendedSongs() async { return playlistSongs.take(15).toList(); } catch (e, stackTrace) { - logger.log('Error in getRecommendedSongs:$e\n$stackTrace'); + logger.log('Error in getRecommendedSongs', e, stackTrace); return []; } } @@ -338,7 +338,7 @@ Future>> getSkipSegments(String id) async { return []; } } catch (e, stack) { - logger.log('Error in getSkipSegments: $e $stack'); + logger.log('Error in getSkipSegments', e, stack); return []; } } @@ -428,7 +428,7 @@ Future getSongManifest(String songId) async { final audioStream = manifest.audioOnly.withHighestBitrate(); return audioStream; } catch (e, stackTrace) { - logger.log('Error while getting song streaming manifest:$e\n$stackTrace'); + logger.log('Error while getting song streaming manifest', e, stackTrace); rethrow; // Rethrow the exception to allow the caller to handle it } } @@ -457,7 +457,7 @@ Future getSong(String songId, bool isLive) async { return await getAudioUrl(songId, isQualityChanged, cacheKey); } } catch (e, stackTrace) { - logger.log('Error while getting song streaming URL:$e\n$stackTrace'); + logger.log('Error while getting song streaming URL', e, stackTrace); rethrow; } } @@ -510,7 +510,7 @@ Future> getSongDetails( final song = await yt.videos.get(songId); return returnSongLayout(songIndex, song); } catch (e, stackTrace) { - logger.log('Error while getting song details:$e\n$stackTrace'); + logger.log('Error while getting song details', e, stackTrace); rethrow; } } @@ -589,11 +589,14 @@ Future _downloadAndSaveArtworkFile(String url, String filePath) async { await file.writeAsBytes(response.bodyBytes); return file; } else { - logger - .log('Failed to download file. Status code: ${response.statusCode}'); + logger.log( + 'Failed to download file. Status code: ${response.statusCode}', + null, + null, + ); } } catch (e, stackTrace) { - logger.log('Error downloading and saving file: $e\n$stackTrace'); + logger.log('Error downloading and saving file', e, stackTrace); } return null; diff --git a/lib/main.dart b/lib/main.dart index f4ee901f0..7621a463d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -142,7 +142,7 @@ class _MusifyState extends State { yield LicenseEntryWithLineBreaks(['google_fonts'], license1); }); } catch (e, stackTrace) { - logger.log('License Registration Error:$e\n$stackTrace'); + logger.log('License Registration Error', e, stackTrace); } } @@ -301,6 +301,6 @@ Future initialisation() async { tapOpensFile: true, ); } catch (e, stackTrace) { - logger.log('Initialization Error:$e\n$stackTrace'); + logger.log('Initialization Error', e, stackTrace); } } diff --git a/lib/screens/home_page.dart b/lib/screens/home_page.dart index 98430bc7c..22af6646b 100644 --- a/lib/screens/home_page.dart +++ b/lib/screens/home_page.dart @@ -65,7 +65,11 @@ class _HomePageState extends State { if (snapshot.connectionState == ConnectionState.waiting) { return _buildLoadingWidget(); } else if (snapshot.hasError) { - logger.log('Error in _buildSuggestedPlaylistsWidget: ${snapshot.error}'); + logger.log( + 'Error in _buildSuggestedPlaylistsWidget', + snapshot.error, + snapshot.stackTrace, + ); return _buildErrorWidget(context); } else if (!snapshot.hasData || snapshot.data!.isEmpty) { return const SizedBox.shrink(); @@ -145,7 +149,9 @@ class _HomePageState extends State { case ConnectionState.done: if (snapshot.hasError) { logger.log( - 'Error in _buildRecommendedSongsAndArtists: ${snapshot.error}', + 'Error in _buildRecommendedSongsAndArtists', + snapshot.error, + snapshot.stackTrace, ); return _buildErrorWidget(context); } diff --git a/lib/screens/playlists_page.dart b/lib/screens/playlists_page.dart index 7be1beed7..b48320e48 100644 --- a/lib/screens/playlists_page.dart +++ b/lib/screens/playlists_page.dart @@ -83,7 +83,11 @@ class _PlaylistsPageState extends State { if (snapshot.connectionState == ConnectionState.waiting) { return const Spinner(); } else if (snapshot.hasError) { - logger.log('Error on playlists page: ${snapshot.error}'); + logger.log( + 'Error on playlists page', + snapshot.error, + snapshot.stackTrace, + ); return Center( child: Text(context.l10n!.error), ); diff --git a/lib/screens/search_page.dart b/lib/screens/search_page.dart index fe6d8fe20..abd6f3e4f 100644 --- a/lib/screens/search_page.dart +++ b/lib/screens/search_page.dart @@ -52,7 +52,7 @@ class _SearchPageState extends State { try { _searchResult = await fetchSongsList(query); } catch (e, stackTrace) { - logger.log('Error while searching online songs:$e\n$stackTrace'); + logger.log('Error while searching online songs', e, stackTrace); } if (_fetchingSongs.value) { diff --git a/lib/screens/user_added_playlists_page.dart b/lib/screens/user_added_playlists_page.dart index b14d1383f..fa156dec9 100644 --- a/lib/screens/user_added_playlists_page.dart +++ b/lib/screens/user_added_playlists_page.dart @@ -137,8 +137,11 @@ class _UserPlaylistsPageState extends State { if (snapshot.connectionState == ConnectionState.waiting) { return const Spinner(); } else if (snapshot.hasError) { - logger - .log('Error on user playlists page: ${snapshot.error}'); + logger.log( + 'Error on user playlists page', + snapshot.error, + snapshot.stackTrace, + ); return Center( child: Text(context.l10n!.error), ); diff --git a/lib/services/audio_service.dart b/lib/services/audio_service.dart index c5d5497cd..371937c01 100644 --- a/lib/services/audio_service.dart +++ b/lib/services/audio_service.dart @@ -35,7 +35,7 @@ class MusifyAudioHandler extends BaseAudioHandler { try { audioPlayer.setAudioSource(_playlist); } catch (e, stackTrace) { - logger.log('Error in setNewPlaylist:$e\n$stackTrace'); + logger.log('Error in setNewPlaylist', e, stackTrace); } _initialize(); @@ -171,7 +171,7 @@ class MusifyAudioHandler extends BaseAudioHandler { } }); } catch (e, stackTrace) { - logger.log('Error initializing audio session:$e\n$stackTrace'); + logger.log('Error initializing audio session', e, stackTrace); } } @@ -220,7 +220,7 @@ class MusifyAudioHandler extends BaseAudioHandler { } await audioPlayer.play(); } catch (e, stackTrace) { - logger.log('Error playing song:$e\n$stackTrace'); + logger.log('Error playing song', e, stackTrace); } } @@ -307,7 +307,7 @@ class MusifyAudioHandler extends BaseAudioHandler { await audioPlayer.setAudioSource(_audioSource); } catch (e, stackTrace) { - logger.log('Error checking sponsor block:$e\n$stackTrace'); + logger.log('Error checking sponsor block', e, stackTrace); } } diff --git a/lib/services/logger_service.dart b/lib/services/logger_service.dart index dc83cd942..46a5310aa 100644 --- a/lib/services/logger_service.dart +++ b/lib/services/logger_service.dart @@ -6,9 +6,9 @@ class Logger { String _logs = ''; int _logCount = 0; - void log(String message) { + void log(String errorLocation, Object? error, StackTrace? stackTrace) { final timestamp = DateTime.now().toString(); - final logMessage = '[$timestamp] $message'; + final logMessage = '[$timestamp] $errorLocation:$error\n$stackTrace'; debugPrint(logMessage); _logs += '$logMessage\n'; _logCount++; @@ -23,7 +23,7 @@ class Logger { return '${context.l10n!.copyLogsNoLogs}.'; } } catch (e, stackTrace) { - log('Error copying logs:$e\n$stackTrace'); + log('Error copying logs', e, stackTrace); return 'Error: $e'; } } diff --git a/lib/services/update_manager.dart b/lib/services/update_manager.dart index b07fe1867..bd9201dd0 100644 --- a/lib/services/update_manager.dart +++ b/lib/services/update_manager.dart @@ -106,10 +106,12 @@ Future checkAppUpdates(BuildContext context) async { } else { logger.log( 'Fetch update API call returned status code ${response.statusCode}', + null, + null, ); } } catch (e, stackTrace) { - logger.log('Error in checkAppUpdates:$e\n$stackTrace'); + logger.log('Error in checkAppUpdates', e, stackTrace); } } @@ -131,7 +133,7 @@ Future downloadAppUpdates(Map map) async { }, ); } catch (e, stackTrace) { - logger.log('Error in downloadAppUpdates:$e\n$stackTrace'); + logger.log('Error in downloadAppUpdates', e, stackTrace); } } @@ -176,7 +178,7 @@ Future checkNecessaryPermissions(BuildContext context) async { try { await Permission.storage.request(); } catch (e, stackTrace) { - logger.log('Error while requesting permissions:$e\n$stackTrace'); + logger.log('Error while requesting permissions', e, stackTrace); showToast( context, '${context.l10n!.errorWhileRequestingPerms} + $e',