Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flush logger IOSink. #229

Merged
merged 1 commit into from Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions 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.
Expand Down
6 changes: 6 additions & 0 deletions packages/fuchsia_ctl/lib/src/logger.dart
Expand Up @@ -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<void> flush() async {
await out.flush();
}
}

/// Transforms a [message] with [level] to a string that contains the DateTime,
Expand Down
3 changes: 3 additions & 0 deletions packages/fuchsia_ctl/lib/src/ssh_client.dart
Expand Up @@ -146,6 +146,9 @@ class SshClient {
stdoutSubscription.asFuture<void>(),
stderrSubscription.asFuture<void>(),
]);

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();
Expand Down
4 changes: 2 additions & 2 deletions packages/fuchsia_ctl/test/logger_test.dart
Expand Up @@ -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'));
Expand Down Expand Up @@ -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'));
Expand Down