Clean up logs

This commit is contained in:
Ming Ming 2021-04-28 04:06:16 +08:00
parent f4ade24950
commit 63772e6e17
15 changed files with 42 additions and 30 deletions

View file

@ -73,7 +73,7 @@ class AppPasswordExchangeBloc
final appPwd = await api_util.exchangePassword(account);
yield AppPasswordExchangeBlocSuccess(appPwd);
} catch (e, stacktrace) {
_log.severe("[_exchangePassword] Failed while exchanging password", e,
_log.shout("[_exchangePassword] Failed while exchanging password", e,
stacktrace);
yield AppPasswordExchangeBlocFailure(e);
}

View file

@ -52,7 +52,7 @@ abstract class AlbumItem {
case AlbumFileItem._type:
return AlbumFileItem.fromJson(content.cast<String, dynamic>());
default:
_log.severe("[fromJson] Unknown type: $type");
_log.shout("[fromJson] Unknown type: $type");
throw ArgumentError.value(type, "type");
}
}
@ -406,11 +406,10 @@ class AlbumCachedDataSource implements AlbumDataSource {
}
_log.info(
"[get] Remote content updated for ${AppDbAlbumEntry.toPath(account, albumFile)}");
} on CacheNotFoundException catch (_) {
// normal when there's no cache
} catch (e, stacktrace) {
// no cache
if (e is! CacheNotFoundException) {
_log.severe("[get] Cache failure", e, stacktrace);
}
_log.shout("[get] Cache failure", e, stacktrace);
}
// no cache

View file

@ -623,11 +623,10 @@ class FileCachedDataSource implements FileDataSource {
}
_log.info(
"[list] Remote content updated for ${AppDbFileEntry.toPath(account, f)}");
} on CacheNotFoundException catch (_) {
// normal when there's no cache
} catch (e, stacktrace) {
// no cache
if (e is! CacheNotFoundException) {
_log.severe("[list] Cache failure", e, stacktrace);
}
_log.shout("[list] Cache failure", e, stacktrace);
}
// no cache
@ -638,7 +637,7 @@ class FileCachedDataSource implements FileDataSource {
try {
await _cleanUpCachedDir(account, remote, cache);
} catch (e, stacktrace) {
_log.severe("[list] Failed while _cleanUpCachedList", e, stacktrace);
_log.shout("[list] Failed while _cleanUpCachedList", e, stacktrace);
// ignore error
}
}

View file

@ -15,7 +15,7 @@ class WebdavFileParser {
element.matchQualifiedName("multistatus",
prefix: "DAV:", namespaces: _namespaces));
} catch (_) {
_log.severe("[call] Missing element: multistatus");
_log.shout("[call] Missing element: multistatus");
rethrow;
}
}();
@ -27,7 +27,7 @@ class WebdavFileParser {
try {
return _toFile(element);
} catch (e, stacktrace) {
_log.severe("[call] Failed parsing XML", e, stacktrace);
_log.shout("[call] Failed parsing XML", e, stacktrace);
return null;
}
})

View file

@ -36,7 +36,7 @@ class MetadataLoader implements itf.MetadataLoader {
final response =
await Api(account).files().get(path: api_util.getFileUrlRelative(file));
if (!response.isGood) {
_log.severe("[forceLoadFile] Failed requesting server: $response");
_log.severe("[loadNewFile] Failed requesting server: $response");
throw ApiException(
response: response,
message: "Failed communicating with server: ${response.statusCode}");

View file

@ -25,7 +25,7 @@ class ListAlbum {
albumRepo.cleanUp(account, albumFiles);
} catch (e, stacktrace) {
// not important, log and ignore
_log.severe("[call] Failed while cleanUp", e, stacktrace);
_log.shout("[call] Failed while cleanUp", e, stacktrace);
}
return albums;
} catch (e) {

View file

@ -34,7 +34,7 @@ class Remove {
await UpdateAlbum(albumRepo)(account, a.copyWith(items: newItems));
}
} catch (e, stacktrace) {
_log.severe(
_log.shout(
"[_cleanUpAlbums] Failed while updating album", e, stacktrace);
// continue to next album
}

View file

@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/file.dart';
@ -22,7 +23,11 @@ class ScanDir {
yield* this(account, i);
}
} catch (e, stacktrace) {
_log.severe("[call] Failed scanning \"${root.path}\"", e, stacktrace);
_log.shout(
"[call] Failed while listing dir" +
(kDebugMode ? ": ${root.path}" : ""),
e,
stacktrace);
// for some reason exception thrown here can't be caught outside
// rethrow;
yield e;

View file

@ -42,7 +42,7 @@ class UpdateMetadata {
await UpdateAlbum(albumRepo)(account, a.copyWith(items: newItems));
}
} catch (e, stacktrace) {
_log.severe(
_log.shout(
"[_cleanUpAlbums] Failed while updating album", e, stacktrace);
// continue to next album
}

View file

@ -54,7 +54,7 @@ class UpdateMissingMetadata {
AlbumRepo(AlbumCachedDataSource()))(account, file, metadataObj);
yield file;
} catch (e, stacktrace) {
_log.severe("[call] Failed while getting metadata", e, stacktrace);
_log.shout("[call] Failed while getting metadata", e, stacktrace);
yield e;
}
}

View file

@ -238,7 +238,7 @@ class _AlbumViewerState extends State<AlbumViewer>
_transformItems();
});
}).catchError((e, stacktrace) {
_log.severe("[_onSelectionRemovePressed] Failed while updating album", e,
_log.shout("[_onSelectionRemovePressed] Failed while updating album", e,
stacktrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(

View file

@ -1,4 +1,5 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@ -335,8 +336,9 @@ class _HomeAlbumsState extends State<HomeAlbums> {
try {
await Remove(fileRepo, albumRepo)(widget.account, f);
} catch (e, stacktrace) {
_log.severe(
"[_onSelectionAppBarDeletePressed] Failed while removing file: ${f.path}",
_log.shout(
"[_onSelectionAppBarDeletePressed] Failed while removing file" +
(kDebugMode ? ": ${f.path}" : ""),
e,
stacktrace);
failures.add(f);

View file

@ -267,7 +267,7 @@ class _HomePhotosState extends State<HomePhotos>
]),
));
} catch (e, stacktrace) {
_log.severe(
_log.shout(
"[_addSelectedToAlbum] Failed while updating album", e, stacktrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(
@ -299,8 +299,9 @@ class _HomePhotosState extends State<HomePhotos>
try {
await Remove(fileRepo, albumRepo)(widget.account, f);
} catch (e, stacktrace) {
_log.severe(
"[_onSelectionAppBarDeletePressed] Failed while removing file: ${f.path}",
_log.shout(
"[_onSelectionAppBarDeletePressed] Failed while removing file" +
(kDebugMode ? ": ${f.path}" : ""),
e,
stacktrace);
failures.add(f);

View file

@ -576,7 +576,7 @@ class _ViewerState extends State<Viewer> with TickerProviderStateMixin {
duration: k.snackBarDurationNormal,
));
} catch (e, stacktrace) {
_log.severe(
_log.shout(
"[_onDownloadPressed] Failed while downloadFile", e, stacktrace);
controller?.close();
SnackBarManager().showSnackBar(SnackBar(
@ -608,7 +608,10 @@ class _ViewerState extends State<Viewer> with TickerProviderStateMixin {
));
Navigator.of(context).pop();
} catch (e, stacktrace) {
_log.severe("[_onDeletePressed] Failed while remove: ${file.path}", e,
_log.shout(
"[_onDeletePressed] Failed while remove" +
(kDebugMode ? ": ${file.path}" : ""),
e,
stacktrace);
controller?.close();
SnackBarManager().showSnackBar(SnackBar(

View file

@ -226,8 +226,11 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
));
Navigator.of(context).pop();
} catch (e, stacktrace) {
_log.severe("[_onDeletePressed] Failed while remove: ${widget.file.path}",
e, stacktrace);
_log.shout(
"[_onDeletePressed] Failed while remove" +
(kDebugMode ? ": ${widget.file.path}" : ""),
e,
stacktrace);
controller?.close();
SnackBarManager().showSnackBar(SnackBar(
content:
@ -344,7 +347,7 @@ class _ViewerDetailPaneState extends State<ViewerDetailPane> {
items: [...album.items, AlbumFileItem(file: widget.file)],
));
} catch (e, stacktrace) {
_log.severe("[_addToAlbum] Failed while updating album", e, stacktrace);
_log.shout("[_addToAlbum] Failed while updating album", e, stacktrace);
SnackBarManager().showSnackBar(SnackBar(
content: Text(
"${AppLocalizations.of(context).addToAlbumFailureNotification}: "