do a few more remaining todos
Some checks failed
Build Docker and Deploy / Build Docker Container (push) Successful in 52s
Build Docker and Deploy / Run Unit-Tests (push) Failing after 11m24s
Build Docker and Deploy / Deploy to Server (push) Has been skipped

This commit is contained in:
2025-04-18 19:14:36 +02:00
parent 78c895547e
commit 5417796f3f
9 changed files with 123 additions and 58 deletions

View File

@@ -6,10 +6,10 @@ import 'package:xid/xid.dart';
part 'request_log.g.dart';
class RequestLog {
//TODO max size, auto clear old
static const MAX_SIZE = 1024;
static void addRequestException(String name, DateTime tStart, String method, Uri uri, String reqbody, Map<String, String> reqheaders, dynamic e, StackTrace trace) {
Hive.box<SCNRequest>('scn-requests').add(SCNRequest(
_logToBox(SCNRequest(
id: Xid().toString(),
timestampStart: tStart,
timestampEnd: DateTime.now(),
@@ -28,7 +28,7 @@ class RequestLog {
}
static void addRequestAPIError(String name, DateTime t0, String method, Uri uri, String reqbody, Map<String, String> reqheaders, int responseStatusCode, String responseBody, Map<String, String> responseHeaders, APIError apierr) {
Hive.box<SCNRequest>('scn-requests').add(SCNRequest(
_logToBox(SCNRequest(
id: Xid().toString(),
timestampStart: t0,
timestampEnd: DateTime.now(),
@@ -47,7 +47,7 @@ class RequestLog {
}
static void addRequestErrorStatuscode(String name, DateTime t0, String method, Uri uri, String reqbody, Map<String, String> reqheaders, int responseStatusCode, String responseBody, Map<String, String> responseHeaders) {
Hive.box<SCNRequest>('scn-requests').add(SCNRequest(
_logToBox(SCNRequest(
id: Xid().toString(),
timestampStart: t0,
timestampEnd: DateTime.now(),
@@ -66,7 +66,7 @@ class RequestLog {
}
static void addRequestSuccess(String name, DateTime t0, String method, Uri uri, String reqbody, Map<String, String> reqheaders, int responseStatusCode, String responseBody, Map<String, String> responseHeaders) {
Hive.box<SCNRequest>('scn-requests').add(SCNRequest(
_logToBox(SCNRequest(
id: Xid().toString(),
timestampStart: t0,
timestampEnd: DateTime.now(),
@@ -85,7 +85,7 @@ class RequestLog {
}
static void addRequestDecodeError(String name, DateTime t0, String method, Uri uri, String reqbody, Map<String, String> reqheaders, int responseStatusCode, String responseBody, Map<String, String> responseHeaders, Object exc, StackTrace trace) {
Hive.box<SCNRequest>('scn-requests').add(SCNRequest(
_logToBox(SCNRequest(
id: Xid().toString(),
timestampStart: t0,
timestampEnd: DateTime.now(),
@@ -102,6 +102,16 @@ class RequestLog {
stackTrace: trace.toString(),
));
}
static void _logToBox(SCNRequest v) {
if (!Hive.isBoxOpen('scn-requests')) return;
final box = Hive.box<SCNRequest>('scn-requests');
box.add(v);
while (box.length > MAX_SIZE) box.deleteAt(0);
}
}
@HiveType(typeId: 100)