Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/fuchsia_ctl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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