From 1a3ef3390eaf4b42d15197eb0f3d526fa2196c13 Mon Sep 17 00:00:00 2001 From: godofredoc <54371434+godofredoc@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:37:59 -0700 Subject: [PATCH] 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: https://github.com/flutter/flutter/issues/67942 --- packages/fuchsia_ctl/CHANGELOG.md | 4 ++++ packages/fuchsia_ctl/lib/src/logger.dart | 6 ++++++ packages/fuchsia_ctl/lib/src/ssh_client.dart | 3 +++ packages/fuchsia_ctl/test/logger_test.dart | 4 ++-- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/fuchsia_ctl/CHANGELOG.md b/packages/fuchsia_ctl/CHANGELOG.md index 078e394528..43716b97d5 100644 --- a/packages/fuchsia_ctl/CHANGELOG.md +++ b/packages/fuchsia_ctl/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## version:0.0.27 + +- Flush the content of iosink when writing output to a file. + ## version:0.0.26 - Replace amberctl with pkgctl. diff --git a/packages/fuchsia_ctl/lib/src/logger.dart b/packages/fuchsia_ctl/lib/src/logger.dart index b9e71e706e..5f908b3ad3 100644 --- a/packages/fuchsia_ctl/lib/src/logger.dart +++ b/packages/fuchsia_ctl/lib/src/logger.dart @@ -108,6 +108,12 @@ class PrintLogger implements Logger { out.writeln('$message'); } } + + /// Flushes the IOSink to ensure all the data is written. This is specially + /// useful when writing to a file. + Future flush() async { + await out.flush(); + } } /// Transforms a [message] with [level] to a string that contains the DateTime, diff --git a/packages/fuchsia_ctl/lib/src/ssh_client.dart b/packages/fuchsia_ctl/lib/src/ssh_client.dart index 7c1612b074..35d20e4047 100644 --- a/packages/fuchsia_ctl/lib/src/ssh_client.dart +++ b/packages/fuchsia_ctl/lib/src/ssh_client.dart @@ -146,6 +146,9 @@ class SshClient { stdoutSubscription.asFuture(), stderrSubscription.asFuture(), ]); + + await logger.flush(); + // The streams as futures have already completed, so waiting for the // potentially async stream cancellation to complete likely has no benefit. stdoutSubscription.cancel(); diff --git a/packages/fuchsia_ctl/test/logger_test.dart b/packages/fuchsia_ctl/test/logger_test.dart index aff42e2086..8f059d68b2 100644 --- a/packages/fuchsia_ctl/test/logger_test.dart +++ b/packages/fuchsia_ctl/test/logger_test.dart @@ -18,7 +18,7 @@ void main() { logger.info('cdf'); logger.warning('gh'); logger.error('jk'); - await data.flush(); + await logger.flush(); final String content = fs.file('log.txt').readAsStringSync(); expect(content, contains('ERROR jk')); expect(content, contains('INFO cdf')); @@ -48,7 +48,7 @@ void main() { logger.info('cdf'); logger.warning('gh'); logger.error('jk'); - await data.flush(); + await logger.flush(); final String content = fs.file('log.txt').readAsStringSync(); expect(content, contains('ERROR jk')); expect(content, contains('INFO cdf'));