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

[rush-lib] Use pnpm-sync-lib logging APIs to customize the log message for pnpm-sync operations. #4594

Merged
merged 12 commits into from Mar 26, 2024

Conversation

g-chao
Copy link
Contributor

@g-chao g-chao commented Mar 21, 2024

Summary

pnpm-sync-lib now have a logMessage API which allow us to customize the log message printing behavior. Check here to see how it implemented.

So, on Rush side, we can use this API to preventing unexpected log message and customize the log message format.

Details

Generally, there will be four types of message coming from pnpm-sync-lib, there are 'info' | 'warning' | 'error' | 'verbose'.

  1. Normally, we will only print out info message.
  2. error and warning will be printed if there are errors or warnings.
  3. The verbose will be printed out if we pass --debug or --vebose flag to the rush commands.

The pnpm-sync-lib also provides operation metadata in the API, so if don't want the message content from pnpm-sync-lib, we can utilize that metadata to fully customize the log message on the Rush side.

How it was tested

Manually tested on local.

Impacted documentation

N/A

@g-chao g-chao changed the title [rush-lib] Use pnpm-sync-lib log callback to customize the logging behavior for pnpm-sync operations. [rush-lib] Use pnpm-sync-lib logging APIs to customize the log message for pnpm-sync operations. Mar 21, 2024
@g-chao g-chao force-pushed the chao/refactor-pnpm-sync-log-message branch from d9a29be to 28b521d Compare March 21, 2024 20:15
@octogonz
Copy link
Collaborator

octogonz commented Mar 26, 2024

@g-chao I've proposed some upstream changes that should to go in first: tiktok/pnpm-sync#20

The formatting improvements in d490478 rely on that new API.

(details.fileCount === 1 ? 'file' : 'files') +
` in ${Math.round(details.executionTimeInMs)} ms`;

terminal.writeVerboseLine(Colorize.cyan(`pnpm-sync: `) + customMessage);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@g-chao For some reason this doesn't get printed with rush rebuild --verbose. I didn't have time to investigate why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked a little bit, this seems a general bug. Basically, the --verbose is not take effect for rush rebuild command.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is because BaseInstallManager creates its own ConsoleTerminalProvider rather than reusing the existing one:

this._terminalProvider = new ConsoleTerminalProvider();
this._terminal = new Terminal(this._terminalProvider);

Seems this code was introduced in PR #3575 and was probably just an oversight.

@iclanton

Copy link
Collaborator

Choose a reason for hiding this comment

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

The top-level Rush terminal provider is created here:

this._terminalProvider = new ConsoleTerminalProvider();
this._terminal = new Terminal(this._terminalProvider);

It sets verboseEnabled based on the --debug flag not the --verbose flag:

public async execute(args?: string[]): Promise<boolean> {
// debugParameter will be correctly parsed during super.execute(), so manually parse here.
this._terminalProvider.verboseEnabled = this._terminalProvider.debugEnabled =
process.argv.indexOf('--debug') >= 0;

I wonder if this was a historical decision? Maybe because of this definition of --verbose?

  -v, --verbose         Display the logs during the build, rather than just
                        displaying the build status summary

Or maybe because not all commands have the --verbose flag?

I'll discuss it with some other maintainers today.

@dmichon-msft

Copy link
Collaborator

Choose a reason for hiding this comment

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

In afffe7c I have wired up the terminal so that pnpm-sync output is now printed with rush --debug. To unblock this PR, we'll address the problem where --verbose doesn't work in a followup PR.

@g-chao g-chao force-pushed the chao/refactor-pnpm-sync-log-message branch from 3e53b1c to 1d684c0 Compare March 26, 2024 17:01
@octogonz octogonz dismissed iclanton’s stale review March 26, 2024 19:48

Ian's feedback has been addressed

@octogonz octogonz merged commit 5846cb6 into microsoft:main Mar 26, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

None yet

3 participants