mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 07:48:40 +00:00
improve logging
This commit is contained in:
parent
d2b7e4cf9e
commit
5758749bd1
5 changed files with 53 additions and 10 deletions
|
|
@ -115,7 +115,7 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
|||
milliseconds: group.deleteMessagesAfterMilliseconds,
|
||||
),
|
||||
);
|
||||
final affected = await (delete(messages)
|
||||
await (delete(messages)
|
||||
..where(
|
||||
(m) =>
|
||||
m.groupId.equals(group.groupId) &
|
||||
|
|
@ -127,7 +127,6 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
|||
m.createdAt.isSmallerThanValue(deletionTime))),
|
||||
))
|
||||
.go();
|
||||
Log.info('Deleted $affected messages.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class ReceiptsDao extends DatabaseAccessor<TwonlyDB> with _$ReceiptsDaoMixin {
|
|||
return await (select(receipts)..where((t) => t.rowId.equals(id)))
|
||||
.getSingle();
|
||||
} catch (e) {
|
||||
Log.error(e);
|
||||
// ignore error, receipts is already in the database...
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,10 +283,6 @@ class ApiService {
|
|||
request.v0.seq = seq;
|
||||
final requestBytes = request.writeToBuffer();
|
||||
|
||||
Log.info(
|
||||
'Sending ${requestBytes.length} bytes to the server via WebSocket.',
|
||||
);
|
||||
|
||||
if (ensureRetransmission) {
|
||||
await addToRetransmissionBuffer(seq, requestBytes);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@ Future<void> initFCMAfterAuthenticated() async {
|
|||
final storedToken = await storage.read(key: SecureStorageKeys.googleFcm);
|
||||
|
||||
try {
|
||||
if (Platform.isIOS) {
|
||||
final apnsToken = await FirebaseMessaging.instance.getAPNSToken();
|
||||
if (apnsToken == null) {
|
||||
Log.error('Error getting apnsToken');
|
||||
return;
|
||||
}
|
||||
}
|
||||
final fcmToken = await FirebaseMessaging.instance.getToken();
|
||||
if (fcmToken == null) {
|
||||
Log.error('Error getting fcmToken');
|
||||
|
|
|
|||
|
|
@ -18,10 +18,24 @@ void initLogger() {
|
|||
);
|
||||
}
|
||||
});
|
||||
cleanLogFile();
|
||||
}
|
||||
|
||||
class Log {
|
||||
static void error(Object? message, [Object? error, StackTrace? stackTrace]) {
|
||||
static String filterLogMessage(String msg) {
|
||||
if (msg.contains("SqliteException")) {
|
||||
// Do not log data which would be inserted into the DB.
|
||||
return msg.substring(0, msg.indexOf("parameters: "));
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
static void error(
|
||||
Object? messageInput, [
|
||||
Object? error,
|
||||
StackTrace? stackTrace,
|
||||
]) {
|
||||
final message = filterLogMessage('$messageInput');
|
||||
if (globalAllowErrorTrackingViaSentry) {
|
||||
try {
|
||||
throw Exception(message);
|
||||
|
|
@ -32,11 +46,21 @@ class Log {
|
|||
Logger(_getCallerSourceCodeFilename()).shout(message, error, stackTrace);
|
||||
}
|
||||
|
||||
static void warn(Object? message, [Object? error, StackTrace? stackTrace]) {
|
||||
static void warn(
|
||||
Object? messageInput, [
|
||||
Object? error,
|
||||
StackTrace? stackTrace,
|
||||
]) {
|
||||
final message = filterLogMessage('$messageInput');
|
||||
Logger(_getCallerSourceCodeFilename()).warning(message, error, stackTrace);
|
||||
}
|
||||
|
||||
static void info(Object? message, [Object? error, StackTrace? stackTrace]) {
|
||||
static void info(
|
||||
Object? messageInput, [
|
||||
Object? error,
|
||||
StackTrace? stackTrace,
|
||||
]) {
|
||||
final message = filterLogMessage('$messageInput');
|
||||
Logger(_getCallerSourceCodeFilename()).fine(message, error, stackTrace);
|
||||
}
|
||||
}
|
||||
|
|
@ -77,6 +101,23 @@ Future<void> _writeLogToFile(LogRecord record) async {
|
|||
});
|
||||
}
|
||||
|
||||
Future<void> cleanLogFile() async {
|
||||
final directory = await getApplicationSupportDirectory();
|
||||
final logFile = File('${directory.path}/app.log');
|
||||
|
||||
if (logFile.existsSync()) {
|
||||
final lines = await logFile.readAsLines();
|
||||
|
||||
if (lines.length <= 5000) return;
|
||||
|
||||
final removeCount = lines.length - 5000;
|
||||
final remaining = lines.sublist(removeCount);
|
||||
|
||||
final sink = logFile.openWrite()..writeAll(remaining, '\n');
|
||||
await sink.close();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> deleteLogFile() async {
|
||||
final directory = await getApplicationSupportDirectory();
|
||||
final logFile = File('${directory.path}/app.log');
|
||||
|
|
|
|||
Loading…
Reference in a new issue