Skip to content

Commit 1a3ef33

Browse files
authored
Flush logger IOSink. (#229)
If we are writing to a file sometimes the content is incomplete because not all the output has been written to the file. Bug: flutter/flutter#67942
1 parent d6a5498 commit 1a3ef33

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

packages/fuchsia_ctl/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## version:0.0.27
4+
5+
- Flush the content of iosink when writing output to a file.
6+
37
## version:0.0.26
48

59
- Replace amberctl with pkgctl.

packages/fuchsia_ctl/lib/src/logger.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ class PrintLogger implements Logger {
108108
out.writeln('$message');
109109
}
110110
}
111+
112+
/// Flushes the IOSink to ensure all the data is written. This is specially
113+
/// useful when writing to a file.
114+
Future<void> flush() async {
115+
await out.flush();
116+
}
111117
}
112118

113119
/// Transforms a [message] with [level] to a string that contains the DateTime,

packages/fuchsia_ctl/lib/src/ssh_client.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ class SshClient {
146146
stdoutSubscription.asFuture<void>(),
147147
stderrSubscription.asFuture<void>(),
148148
]);
149+
150+
await logger.flush();
151+
149152
// The streams as futures have already completed, so waiting for the
150153
// potentially async stream cancellation to complete likely has no benefit.
151154
stdoutSubscription.cancel();

packages/fuchsia_ctl/test/logger_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void main() {
1818
logger.info('cdf');
1919
logger.warning('gh');
2020
logger.error('jk');
21-
await data.flush();
21+
await logger.flush();
2222
final String content = fs.file('log.txt').readAsStringSync();
2323
expect(content, contains('ERROR jk'));
2424
expect(content, contains('INFO cdf'));
@@ -48,7 +48,7 @@ void main() {
4848
logger.info('cdf');
4949
logger.warning('gh');
5050
logger.error('jk');
51-
await data.flush();
51+
await logger.flush();
5252
final String content = fs.file('log.txt').readAsStringSync();
5353
expect(content, contains('ERROR jk'));
5454
expect(content, contains('INFO cdf'));

0 commit comments

Comments
 (0)