Add logging

This commit is contained in:
2024-05-27 06:51:33 +00:00
committed by GitHub
parent bb4ba0456d
commit 89b2d33f76
5 changed files with 27 additions and 24 deletions

View File

@@ -38,8 +38,9 @@ class ImageWithContextMenu extends StatelessWidget {
callback: () async {
try {
await copyImageToClipboard(data, fmt);
} catch (err) {
_log.warning("Failed to copy image to clipboard:", err);
} catch (err, stack) {
_log.warning(
"Failed to copy image to clipboard: $err\n$stack");
}
})
];
@@ -59,12 +60,13 @@ class ImageWithContextMenu extends StatelessWidget {
try {
platformPath.saveFile(fileName!, fmt.toMimeType(), data,
dir: dir ?? "");
} catch (err) {
_log.warning("Failed to save image:", err);
} catch (err, stack) {
_log.warning("Failed to save image: $err\n$stack");
}
}));
}
if ((isNsfw != null && changeNsfw != null) || (isAd != null && changeAd != null)) {
if ((isNsfw != null && changeNsfw != null) ||
(isAd != null && changeAd != null)) {
list.add(MenuSeparator());
}
if (isNsfw != null && changeNsfw != null) {

View File

@@ -153,8 +153,8 @@ class _Thumbnail extends State<Thumbnail> {
});
return;
}
} catch (e) {
_log.warning("Failed to get cache for $_originalUrl: $e");
} catch (e, stack) {
_log.warning("Failed to get cache for $_originalUrl: $e\n$stack");
}
}
final re = await api.getThumbnail(_fileId!,
@@ -175,8 +175,8 @@ class _Thumbnail extends State<Thumbnail> {
try {
await imageCaches.putCache(
_originalUrl!, data, re.response.headers.map, _uri);
} catch (e) {
_log.warning("Failed to put cache for $_originalUrl: $e");
} catch (e, stack) {
_log.warning("Failed to put cache for $_originalUrl: $e\n$stack");
}
}
setState(() {
@@ -262,23 +262,23 @@ class _Thumbnail extends State<Thumbnail> {
case _ThumbnailMenu.copyImage:
try {
copyImageToClipboard(_data!, ImageFmt.jpg);
} catch (err) {
_log.warning("Failed to copy image to clipboard:", err);
} catch (err, stack) {
_log.warning("Failed to copy image to clipboard: $err\n$stack");
}
break;
case _ThumbnailMenu.copyImgUrl:
try {
copyTextToClipboard(_uri!);
} catch (err) {
_log.warning("Failed to copy image url to clipboard:", err);
} catch (err, stack) {
_log.warning("Failed to copy image url to clipboard: $err\n$stack");
}
break;
case _ThumbnailMenu.saveAs:
try {
await platformPath.saveFile(_fileName!, "image/jpeg", _data!,
dir: _dir);
} catch (err) {
_log.warning("Failed to save image:", err);
} catch (err, stack) {
_log.warning("Failed to save image: $err\n$stack");
}
break;
case _ThumbnailMenu.markAsNsfw:

View File

@@ -144,7 +144,7 @@ class ImageCaches {
needDeleted.add(url);
}
} catch (e) {
_log.warning("Failed to check $p is exists or not. Url: $url");
_log.warning("Failed to check $p is exists or not. Url: $url. $e");
}
}
offset += records.length;
@@ -181,7 +181,7 @@ class ImageCaches {
await _db!.rawUpdate(
"UPDATE images SET last_used = ? WHERE url = ?;", [lastUsed, uri]);
} catch (e) {
_log.warning("Failed to set last_used to $lastUsed for $uri.");
_log.warning("Failed to set last_used to $lastUsed for $uri: $e");
}
final f = _fs.file(p);
final da = await f.readAsBytes();
@@ -252,7 +252,7 @@ class ImageCaches {
try {
await f.delete();
} catch (e) {
_log.warning("Failed to delete $p");
_log.warning("Failed to delete $p: $e");
}
}
offset += records.length;

View File

@@ -92,8 +92,8 @@ class DioImage extends ImageProvider<DioImage> {
final buffer = await ui.ImmutableBuffer.fromUint8List(cache!.$1);
return decode(buffer);
}
} catch (e) {
_log.warning("Failed to get cache for ${url.toString()}: $e");
} catch (e, stack) {
_log.warning("Failed to get cache for ${url.toString()}: $e\n$stack");
}
}
@@ -128,8 +128,8 @@ class DioImage extends ImageProvider<DioImage> {
try {
await imageCaches.putCache(url.toString(), bytes,
response.headers.map, response.realUri.toString());
} catch (e) {
_log.warning("Failed to put cache for ${url.toString()}: $e");
} catch (e, stack) {
_log.warning("Failed to put cache for ${url.toString()}: $e\n$stack");
}
}

View File

@@ -190,8 +190,9 @@ class TaskManager {
} else if (type == "ping") {
_channel?.sink.add("{\"type\":\"pong\"}");
}
} catch (e) {
_log.warning("Error processing task message: $e, event: $event");
} catch (e, stack) {
_log.warning(
"Error processing task message: $e, event: $event\n$stack");
}
}, onError: (e) {
_log.warning("Task websocket error: $e");