Skip to content
Merged
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
7 changes: 5 additions & 2 deletions lib/cmd/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,12 @@ class StartCommand extends Command {
try {
const args = [ '-n', '100', stderr ];
this.logger.error('tail %s', args.join(' '));
const [ stdout ] = await execFile('tail', args);
const [ headStdout ] = await execFile('head', args);
const [ tailStdout ] = await execFile('tail', args);
this.logger.error('Got error when startup: ');
this.logger.error(stdout);
this.logger.error(headStdout);
this.logger.error('...');
this.logger.error(tailStdout);
Comment on lines +268 to +273
Copy link

Choose a reason for hiding this comment

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

Optimize error log retrieval and improve logging structure.

- const [ headStdout ] = await execFile('head', args);
- const [ tailStdout ] = await execFile('tail', args);
- this.logger.error('Got error when startup: ');
- this.logger.error(headStdout);
- this.logger.error('...');
- this.logger.error(tailStdout);
+ const [ combinedStdout ] = await execFile('sh', ['-c', `head ${args.join(' ')} && echo '...' && tail ${args.join(' ')}`]);
+ this.logger.error('Startup error log:\\n%s', combinedStdout);

This change combines the head and tail commands into a single shell command, reducing the number of file reads. Additionally, it structures the error log into a single message, making it clearer and more concise.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const [ headStdout ] = await execFile('head', args);
const [ tailStdout ] = await execFile('tail', args);
this.logger.error('Got error when startup: ');
this.logger.error(stdout);
this.logger.error(headStdout);
this.logger.error('...');
this.logger.error(tailStdout);
const [ combinedStdout ] = await execFile('sh', ['-c', `head ${args.join(' ')} && echo '...' && tail ${args.join(' ')}`]);
this.logger.error('Startup error log:\n%s', combinedStdout);

} catch (err) {
this.logger.error('ignore tail error: %s', err);
}
Expand Down