do a few more remaining todos
This commit is contained in:
@@ -229,4 +229,8 @@ class AppAuth extends ChangeNotifier implements TokenSource {
|
||||
String getUserID() {
|
||||
return _userID!;
|
||||
}
|
||||
|
||||
String? getClientID() {
|
||||
return _clientID;
|
||||
}
|
||||
}
|
||||
|
@@ -10,69 +10,44 @@ import 'package:path/path.dart' as path;
|
||||
part 'application_log.g.dart';
|
||||
|
||||
class ApplicationLog {
|
||||
//TODO max size, auto clear old
|
||||
static const MAX_SIZE = 2048;
|
||||
|
||||
static void debug(String message, {String? additional, StackTrace? trace}) {
|
||||
(additional != null && additional != '') ? print('[DEBUG] ${message}: ${additional}') : print('[DEBUG] ${message}');
|
||||
|
||||
if (!Hive.isBoxOpen('scn-logs')) return;
|
||||
Hive.box<SCNLog>('scn-logs').add(SCNLog(
|
||||
id: Xid().toString(),
|
||||
timestamp: DateTime.now(),
|
||||
level: SCNLogLevel.debug,
|
||||
message: message,
|
||||
additional: additional ?? '',
|
||||
trace: trace?.toString() ?? '',
|
||||
));
|
||||
_logToBox(SCNLogLevel.debug, message, additional, trace);
|
||||
}
|
||||
|
||||
static void info(String message, {String? additional, StackTrace? trace}) {
|
||||
(additional != null && additional != '') ? print('[INFO] ${message}: ${additional}') : print('[INFO] ${message}');
|
||||
|
||||
if (!Hive.isBoxOpen('scn-logs')) return;
|
||||
Hive.box<SCNLog>('scn-logs').add(SCNLog(
|
||||
id: Xid().toString(),
|
||||
timestamp: DateTime.now(),
|
||||
level: SCNLogLevel.info,
|
||||
message: message,
|
||||
additional: additional ?? '',
|
||||
trace: trace?.toString() ?? '',
|
||||
));
|
||||
_logToBox(SCNLogLevel.info, message, additional, trace);
|
||||
}
|
||||
|
||||
static void warn(String message, {String? additional, StackTrace? trace}) {
|
||||
(additional != null && additional != '') ? print('[WARN] ${message}: ${additional}') : print('[WARN] ${message}');
|
||||
|
||||
if (!Hive.isBoxOpen('scn-logs')) return;
|
||||
Hive.box<SCNLog>('scn-logs').add(SCNLog(
|
||||
id: Xid().toString(),
|
||||
timestamp: DateTime.now(),
|
||||
level: SCNLogLevel.warning,
|
||||
message: message,
|
||||
additional: additional ?? '',
|
||||
trace: trace?.toString() ?? '',
|
||||
));
|
||||
_logToBox(SCNLogLevel.warning, message, additional, trace);
|
||||
}
|
||||
|
||||
static void error(String message, {String? additional, StackTrace? trace}) {
|
||||
(additional != null && additional != '') ? print('[ERROR] ${message}: ${additional}') : print('[ERROR] ${message}');
|
||||
|
||||
if (!Hive.isBoxOpen('scn-logs')) return;
|
||||
Hive.box<SCNLog>('scn-logs').add(SCNLog(
|
||||
id: Xid().toString(),
|
||||
timestamp: DateTime.now(),
|
||||
level: SCNLogLevel.error,
|
||||
message: message,
|
||||
additional: additional ?? '',
|
||||
trace: trace?.toString() ?? '',
|
||||
));
|
||||
_logToBox(SCNLogLevel.error, message, additional, trace);
|
||||
}
|
||||
|
||||
static void fatal(String message, {String? additional, StackTrace? trace}) {
|
||||
(additional != null && additional != '') ? print('[FATAL] ${message}: ${additional}') : print('[FATAL] ${message}');
|
||||
|
||||
_logToBox(SCNLogLevel.fatal, message, additional, trace);
|
||||
}
|
||||
|
||||
static void _logToBox(SCNLogLevel lvl, String message, String? additional, StackTrace? trace) {
|
||||
if (!Hive.isBoxOpen('scn-logs')) return;
|
||||
Hive.box<SCNLog>('scn-logs').add(SCNLog(
|
||||
|
||||
final box = Hive.box<SCNLog>('scn-logs');
|
||||
|
||||
box.add(SCNLog(
|
||||
id: Xid().toString(),
|
||||
timestamp: DateTime.now(),
|
||||
level: SCNLogLevel.fatal,
|
||||
@@ -80,6 +55,8 @@ class ApplicationLog {
|
||||
additional: additional ?? '',
|
||||
trace: trace?.toString() ?? '',
|
||||
));
|
||||
|
||||
while (box.length > MAX_SIZE) box.deleteAt(0);
|
||||
}
|
||||
|
||||
static void writeRawFailure(String message, Map<String, dynamic> extraData) async {
|
||||
|
@@ -5,10 +5,16 @@ import 'package:simplecloudnotifier/state/interfaces.dart';
|
||||
part 'fb_message.g.dart';
|
||||
|
||||
class FBMessageLog {
|
||||
//TODO max size, auto clear old
|
||||
static const MAX_SIZE = 512;
|
||||
|
||||
static void insert(RemoteMessage msg) {
|
||||
Hive.box<FBMessage>('scn-fb-messages').add(FBMessage.fromRemoteMessage(msg));
|
||||
if (!Hive.isBoxOpen('scn-fb-messages')) return;
|
||||
|
||||
final box = Hive.box<FBMessage>('scn-fb-messages');
|
||||
|
||||
box.add(FBMessage.fromRemoteMessage(msg));
|
||||
|
||||
while (box.length > MAX_SIZE) box.deleteAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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