Skip to content

Stream logs to file using process.start. #227

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

Merged
merged 5 commits into from
Oct 16, 2020
Merged

Stream logs to file using process.start. #227

merged 5 commits into from
Oct 16, 2020

Conversation

godofredoc
Copy link
Contributor

Fuchsia_ctl currently uses process.run to run commands this forces the tool to wait until the process
completes to collect the results.

Fuchsia_ctl currently uses process.run to run commands this forcs the
tool to wait until the process completes to collect the results.
@@ -186,7 +189,8 @@ Future<OperationResult> ssh(
identityFilePath: identityFile,
command: args['command'].split(' '),
timeoutMs:
Duration(milliseconds: int.parse(args['timeout-seconds']) * 1000));
Duration(milliseconds: int.parse(args['timeout-seconds']) * 1000),
logFilePath: outputFile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: trailing comma will make this format a bit more nicely

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/// level and message.
String toLogString(String message, {LogLevel level}) {
final StringBuffer buffer = StringBuffer();
buffer.write(DateTime.now().toIso8601String());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
buffer.write(DateTime.now().toIso8601String());
buffer.write(DateTime.now().toUtc().toIso8601String());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Duration timeoutMs = defaultSshTimeoutMs}) async {
Duration timeoutMs = defaultSshTimeoutMs,
String logFilePath,
FileSystem fs}) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: trailing comma for arg list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 138 to 142
if (!logToFile) {
logFile.writeln(log);
} else {
logger.info(log);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we just do logger.info(log) here? Won't it write to the file if it's attached to the IOSink, and otherwise jut write to stdout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. It was implemented like that because logfile adds datetime and log level and all the ssh commands in fuchsia_ctl expects output with no additional prepended.

if (!logToFile) {
logFile.writeln(log);
} else {
logger.warning(log);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to error.

Comment on lines 121 to 123
fileSystem = MemoryFileSystem();
fileSystem.file('logs')..createSync();
logFile = fileSystem.file('logs').openWrite();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's not used below and the output will just be an empty string if no log file is specified.

I think we might be better off having some kind of BufferedLogger class that would allow us to retrieve the buffer as well as writing it to a file if needed.

Alternatively, if we're logging this to a file/stdout, do we really need to return stdout/stderr back to the caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed from here and moved the functionality to the logger class.

@@ -14,10 +14,11 @@ dependencies:
file: ^5.0.10
meta: ^1.1.7
path: ^1.6.4
pedantic: ^1.9.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid having pedantic as a direct dependency - use it as a dev dependency instead. Although this package is not consumed by anyone, this can cause problems if we later need to use some other package that's also using pedantic with an incompatible constraint. Pedantic's semver constraints are really more about the analysis option rules anyway, rather than the unawaited function.

We should just write our own unawaited function, which is literally one line of code, where we need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 7 to 9
void main() {
test('', () async {});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe forgot to save before committing? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep uploaded the version with the tests.

Copy link

@chaselatta chaselatta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After Dan's comments are addressed LGTM.

/// LogLevel for messages instended for debugging.
static const LogLevel debug = LogLevel._(0, 'DEBUG');

/// LogLevel for messages instended to provide information about the exection.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo in execution

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@godofredoc godofredoc merged commit d94c3ef into flutter:master Oct 16, 2020
stuartmorgan-g pushed a commit that referenced this pull request Oct 31, 2024
#227)

* oops

* Fix scientific notation parsing

* Update packages/vector_graphics_compiler/test/parsers_test.dart

Co-authored-by: Jonah Williams <jonahwilliams@google.com>

* Fix up analysis issues and half implemented test

---------

Co-authored-by: Jonah Williams <jonahwilliams@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants