do a few more remaining todos
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user