mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-03-03 13:36:47 +00:00
exclusive lock for logging on the same process
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
This commit is contained in:
parent
fb1e286cf9
commit
6df40e93df
2 changed files with 25 additions and 18 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
## 0.0.96
|
## 0.0.96
|
||||||
|
|
||||||
Feature: Show link in chat if the saved media file contains one
|
- Feature: Show link in chat if the saved media file contains one
|
||||||
Improve: Verification badge for groups
|
- Improve: Verification badge for groups
|
||||||
Improve: Huge reduction in app size
|
- Improve: Huge reduction in app size
|
||||||
Fix: Crash on older devices when compressing a video
|
- Fix: Crash on older devices when compressing a video
|
||||||
Fix: Problem with decrypting messages fixed
|
- Fix: Problem with decrypting messages fixed
|
||||||
|
|
||||||
## 0.0.93
|
## 0.0.93
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'dart:io';
|
||||||
import 'package:clock/clock.dart';
|
import 'package:clock/clock.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
import 'package:mutex/mutex.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
import 'package:twonly/globals.dart';
|
import 'package:twonly/globals.dart';
|
||||||
|
|
@ -85,6 +86,8 @@ Future<String> readLast1000Lines() async {
|
||||||
return all.sublist(start).join('\n');
|
return all.sublist(start).join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mutex sameProcessProtection = Mutex();
|
||||||
|
|
||||||
Future<void> _writeLogToFile(LogRecord record) async {
|
Future<void> _writeLogToFile(LogRecord record) async {
|
||||||
final directory = await getApplicationSupportDirectory();
|
final directory = await getApplicationSupportDirectory();
|
||||||
final logFile = File('${directory.path}/app.log');
|
final logFile = File('${directory.path}/app.log');
|
||||||
|
|
@ -95,6 +98,9 @@ Future<void> _writeLogToFile(LogRecord record) async {
|
||||||
final logMessage =
|
final logMessage =
|
||||||
'${clock.now().toString().split(".")[0]} ${record.level.name} [twonly] ${record.loggerName} > ${record.message}\n';
|
'${clock.now().toString().split(".")[0]} ${record.level.name} [twonly] ${record.loggerName} > ${record.message}\n';
|
||||||
|
|
||||||
|
// > Note that this does not actually lock the file for access. Also note that advisory locks are on a process level.
|
||||||
|
// > This means that several isolates in the same process can obtain an exclusive lock on the same file.
|
||||||
|
return sameProcessProtection.protect(() async {
|
||||||
final raf = await logFile.open(mode: FileMode.writeOnlyAppend);
|
final raf = await logFile.open(mode: FileMode.writeOnlyAppend);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -109,6 +115,7 @@ Future<void> _writeLogToFile(LogRecord record) async {
|
||||||
await raf.unlock();
|
await raf.unlock();
|
||||||
await raf.close();
|
await raf.close();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cleanLogFile() async {
|
Future<void> cleanLogFile() async {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue