-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Conversation
Fuchsia_ctl currently uses process.run to run commands this forcs the tool to wait until the process completes to collect the results.
packages/fuchsia_ctl/bin/main.dart
Outdated
@@ -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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buffer.write(DateTime.now().toIso8601String()); | |
buffer.write(DateTime.now().toUtc().toIso8601String()); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (!logToFile) { | ||
logFile.writeln(log); | ||
} else { | ||
logger.info(log); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to error.
fileSystem = MemoryFileSystem(); | ||
fileSystem.file('logs')..createSync(); | ||
logFile = fileSystem.file('logs').openWrite(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
packages/fuchsia_ctl/pubspec.yaml
Outdated
@@ -14,10 +14,11 @@ dependencies: | |||
file: ^5.0.10 | |||
meta: ^1.1.7 | |||
path: ^1.6.4 | |||
pedantic: ^1.9.2 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
void main() { | ||
test('', () async {}); | ||
} |
There was a problem hiding this comment.
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? :)
There was a problem hiding this comment.
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.
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo in execution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
#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>
Fuchsia_ctl currently uses process.run to run commands this forces the tool to wait until the process
completes to collect the results.