Skip to content

Conversation

mho22
Copy link
Collaborator

@mho22 mho22 commented Jul 28, 2025

Motivation for the change, related issues

The former intent of this pull request was to replace the console logs from the Xdebug bridge.
Console logs were replaced by Logger logs and a filter by severity was added.

The CLIs verbosity argument is now related to its CLI LogVerbosity associated with a Logger LogSeverity. This setup will filter the related logs.

Implementation details

The Playground CLI and Xdebug-bridge CLI now have a LogVerbosity variable :

const LogVerbosity = {
	Quiet: { name: 'quiet', severity: LogSeverity.Fatal },
	Normal: { name: 'normal', severity: LogSeverity.Info },
	Debug: { name: 'debug', severity: LogSeverity.Debug },
} as const;

The yargs verbosity option is now as follows :

.option('verbosity', {
	type: 'string',
	describe: 'Output logs',
	choices: Object.values(LogVerbosity).map(
		(verbosity) => verbosity.name
	),
	default: 'normal',
})

And the Logs are filtered based on the verbosity argument :

if (args.verbosity) {
    const severity = Object.values(LogVerbosity).find(
    	(v) => v.name === args.verbosity
    )!.severity;
    logger.filterBySeverity(severity);
}

The logger will then log the message based on if the severity level is equal or lower than the verbosity's severity level :

for (const handler of this.handlers) {
	if (logWithSeverity.severity.level <= this.severity.level) {
		handler(logWithSeverity, ...args);
	}
}

Testing Instructions (or ideally a Blueprint)

Normal mode

> nx run php-wasm-xdebug-bridge:dev

> node --no-warnings --experimental-wasm-stack-switching --experimental-wasm-jspi --loader=./packages/meta/src/node-es-module-loader/loader.mts ./packages/php-wasm/xdebug-bridge/src/cli.ts

Starting XDebug Bridge...
Connect Chrome DevTools to CDP at:
devtools://devtools/bundled/inspector.html?ws=localhost:9229

Chrome connected! Initializing Xdebug receiver...
XDebug receiver running on port 9003
Running a PHP script with Xdebug enabled...

Quiet mode

> nx run php-wasm-xdebug-bridge:dev --verbosity quiet

> node --no-warnings --experimental-wasm-stack-switching --experimental-wasm-jspi --loader=./packages/meta/src/node-es-module-loader/loader.mts ./packages/php-wasm/xdebug-bridge/src/cli.ts --verbosity quiet

...silence...

Debug mode

> nx run php-wasm-xdebug-bridge:dev --verbosity debug

> node --no-warnings --experimental-wasm-stack-switching --experimental-wasm-jspi --loader=./packages/meta/src/node-es-module-loader/loader.mts ./packages/php-wasm/xdebug-bridge/src/cli.ts --verbosity debug


Starting XDebug Bridge...
Connect Chrome DevTools to CDP at:
devtools://devtools/bundled/inspector.html?ws=localhost:9229

[CDP][received] {"id":1,"method":"Network.setCacheDisabled","params":{"cacheDisabled":true}}
[CDP][received] {"id":2,"method":"Network.enable","params":{"maxPostDataSize":65536,"reportDirectSocketTraffic":true}}
[CDP][received] {"id":3,"method":"Network.setAttachDebugStack","params":{"enabled":true}}
[CDP][received] {"id":4,"method":"Page.enable","params":{}}
[CDP][received] {"id":5,"method":"Page.getResourceTree","params":{}}
[CDP][received] {"id":6,"method":"Runtime.enable","params":{}}
[CDP][received] {"id":7,"method":"DOM.enable","params":{}}
[CDP][received] {"id":8,"method":"CSS.enable","params":{}}
[CDP][received] {"id":9,"method":"Debugger.enable","params":{"maxScriptsCacheSize":10000000}}
[CDP][received] {"id":10,"method":"Debugger.setPauseOnExceptions","params":{"state":"none"}}
[CDP][received] {"id":11,"method":"Debugger.setAsyncCallStackDepth","params":{"maxDepth":32}}
[CDP][received] {"id":12,"method":"Overlay.enable","params":{}}
[CDP][received] {"id":13,"method":"Overlay.setShowViewportSizeOnResize","params":{"show":true}}
[CDP][received] {"id":14,"method":"Animation.enable","params":{}}
[CDP][received] {"id":15,"method":"Autofill.enable","params":{}}
[CDP][received] {"id":16,"method":"Autofill.setAddresses","params":{"addresses":[]}}
[CDP][received] {"id":17,"method":"Profiler.enable","params":{}}
[CDP][received] {"id":18,"method":"Log.enable","params":{}}
[CDP][received] {"id":19,"method":"Log.startViolationsReport","params":{"config":[{"name":"longTask","threshold":200},{"name":"longLayout","threshold":30},{"name":"blockedEvent","threshold":100},{"name":"blockedParser","threshold":-1},{"name":"handler","threshold":150},{"name":"recurringHandler","threshold":50},{"name":"discouragedAPIUse","threshold":-1}]}}
[CDP][received] {"id":20,"method":"Emulation.setEmulatedMedia","params":{"media":"","features":[{"name":"color-gamut","value":""},{"name":"prefers-color-scheme","value":""},{"name":"forced-colors","value":""},{"name":"prefers-contrast","value":""},{"name":"prefers-reduced-data","value":""},{"name":"prefers-reduced-motion","value":""},{"name":"prefers-reduced-transparency","value":""}]}}
[CDP][received] {"id":21,"method":"Emulation.setEmulatedVisionDeficiency","params":{"type":"none"}}
[CDP][received] {"id":22,"method":"Audits.enable","params":{}}
[CDP][received] {"id":23,"method":"ServiceWorker.enable","params":{}}
[CDP][received] {"id":24,"method":"Inspector.enable","params":{}}
[CDP][received] {"id":25,"method":"Target.setAutoAttach","params":{"autoAttach":true,"waitForDebuggerOnStart":true,"flatten":true}}
[CDP][received] {"id":26,"method":"Target.setDiscoverTargets","params":{"discover":true}}
[CDP][received] {"id":27,"method":"Target.setRemoteLocations","params":{"locations":[{"host":"localhost","port":9229}]}}
[CDP][received] {"id":28,"method":"Runtime.addBinding","params":{"name":"__chromium_devtools_metrics_reporter","executionContextName":"DevTools Performance Metrics"}}
[CDP][received] {"id":29,"method":"Network.clearAcceptedEncodingsOverride","params":{}}
[CDP][received] {"id":30,"method":"Debugger.setBlackboxPatterns","params":{"patterns":["/node_modules/|^node:"],"skipAnonymous":false}}
[CDP][received] {"id":31,"method":"Page.getNavigationHistory","params":{}}
[CDP][received] {"id":32,"method":"DOMDebugger.setBreakOnCSPViolation","params":{"violationTypes":[]}}
[CDP][received] {"id":33,"method":"Debugger.setBreakpointByUrl","params":{"lineNumber":11,"url":"http://[::1]:5173/@fs/Users/mho/Work/Sandbox/Web/js/php-wasm/wordpress-playground/dist/packages/php-wasm/logger/index.js","columnNumber":0,"condition":""}}
[CDP][received] {"id":34,"method":"Debugger.setBreakpointByUrl","params":{"lineNumber":42,"url":"https://sparse.test:5173/@fs/Users/mho/Work/Sandbox/Web/js/php-wasm/wordpress-playground/dist/packages/php-wasm/web/php/jspi/php_8_2.js","columnNumber":68886,"condition":""}}
[CDP][received] {"id":35,"method":"Debugger.setBreakpointByUrl","params":{"lineNumber":4480,"url":"debugger:///VM902 client-CdekbSNg.js","columnNumber":0,"condition":""}}
[CDP][received] {"id":36,"method":"Debugger.setBreakpointByUrl","params":{"lineNumber":2,"url":"file:///Users/mho/Work/Projects/Development/Web/Professional/xdebug/template/php/xdebug.php","columnNumber":0,"condition":""}}
[CDP][received] {"id":37,"method":"Debugger.setBreakpointByUrl","params":{"lineNumber":2,"url":"file://xdebug.php","columnNumber":0,"condition":""}}
[CDP][received] {"id":38,"method":"Debugger.setBreakpointByUrl","params":{"lineNumber":2,"url":"file:///wordpress/xdebug.php","columnNumber":0,"condition":""}}
[CDP][received] {"id":39,"method":"Runtime.runIfWaitingForDebugger","params":{}}
[CDP][received] {"id":40,"method":"Page.setAdBlockingEnabled","params":{"enabled":false}}
[CDP][received] {"id":41,"method":"Emulation.setFocusEmulationEnabled","params":{"enabled":false}}
[CDP][received] {"id":42,"method":"Page.startScreencast","params":{"format":"jpeg","quality":80,"maxWidth":272,"maxHeight":1778}}
Chrome connected! Initializing Xdebug receiver...
XDebug receiver running on port 9003
Running a PHP script with Xdebug enabled...

@mho22 mho22 changed the title [XDebug Bridge] Add --quiet and --verbose options in Xdebug Bridge [XDebug Bridge] Add --quiet and --verbose options in bridge Jul 28, 2025
@mho22
Copy link
Collaborator Author

mho22 commented Aug 4, 2025

I will try to add tests before marking it as ready for review.

@mho22 mho22 marked this pull request as ready for review August 4, 2025 12:15
@adamziel
Copy link
Collaborator

adamziel commented Aug 4, 2025

Maybe --verbosity=quiet|normal|debug or so? That way we won't run into ./run-bridge --quiet --verbose conundrum. Also, we can always call logger.log() and such – output filtering can be done at the logToConsole log handler level (with some refactoring). Then, the CLI package could follow that pattern.

@mho22
Copy link
Collaborator Author

mho22 commented Aug 6, 2025

@adamziel This one was a quite big refactoring. I will need a review on this. A little summary of what I had in mind when I coded these :

  1. I set a LogVerbosity option like you suggested. Directly inside the Logger file. 3 options : quiet, normal and debug.

  2. The default one is debug since debug accepts every severity, like before the refactoring.

  3. When calling filterByVerbosity :

  • if you choose quiet no severity will be printed in the console
  • if you choose normal all severities except debug will be printed in the console.
  • if you choose debug all severities will be printed in the console.
  1. I implemented the --verbosity option in :
  • The Xdebug Bridge CLI
  • The Playground CLI
  1. I implemented tests in :
  • Logger
  • Xdebug Bridge
  • Playground CLI

I therefore have several questions :

  1. The normal verbosity should silence more than only the debug severity ?
  2. Should I add a new --verbosity option in the PHP Wasm CLI too ?
  3. Should I apply these filters to every LogHandlers or only the logToConsole one ?

@adamziel
Copy link
Collaborator

adamziel commented Aug 6, 2025

Things are looking good! I haven't tested it yet at this stage, only left a few comments – this one seems the most important.

@adamziel
Copy link
Collaborator

adamziel commented Aug 6, 2025

The normal verbosity should silence more than only the debug severity ?

I'd say normal includes all the log levels except debug.

Should I add a new --verbosity option in the PHP Wasm CLI too ?

Potentially? But not in this PR, it already covers a lot of ground.

@mho22
Copy link
Collaborator Author

mho22 commented Aug 6, 2025

I'd say normal includes all the log levels except debug.

Done.

Potentially? But not in this PR, it already covers a lot of ground.

Ok! What do you think about using yargs in php-wasm/cli/main.ts and renaming the file to run-cli.ts to maintain consistency across the different CLIs? Let's talk about that in the next pull request maybe.

@adamziel
Copy link
Collaborator

adamziel commented Aug 6, 2025

Ok! What do you think about using yargs in php-wasm/cli/main.ts and renaming the file to run-cli.ts to maintain consistency across the different CLIs? Let's talk about that in the next pull request maybe.

Sounds great for a follow-up PR!

@adamziel
Copy link
Collaborator

adamziel commented Aug 7, 2025

I'll test this and follow up tomorrow

@adamziel
Copy link
Collaborator

adamziel commented Aug 8, 2025

I've left two notes about the code design, and my only other note would be to adjust the PR title and description to reflect the larger logging refactor.

@mho22
Copy link
Collaborator Author

mho22 commented Aug 18, 2025

I added the corrections you asked and modified the bridge to respect the logic from the playground :

  • Removed the LogVerbosity from Logger
  • Added unique level to LogSeverities
  • Replaced filterByVerbosity with filterBySeverity
  • Added a LogVerbosity const in CLIs
  • Filtered logs by severity in CLIs
  • Removed verbosity option from xdebug-bridge/start-bridge.ts ( if bridge is used in code, logger also can be used ).
  • Add tests for the verbosity argument in xdebug-bridge/run-cli.ts
  • Add tests for logs in xdebug-bridge/start-bridge.ts

I will now adjust the pull request title and description.

  • I set the quiet verbosity to be of severity Fatal (its level is 0), so even if the verbosity is set to quiet it should log the fatal error.

@mho22 mho22 changed the title [XDebug Bridge] Add --quiet and --verbose options in bridge [php-wasm] Filter logs by severity in Logger and assign severity based on verbosity argument in CLI Aug 18, 2025
@mho22 mho22 changed the title [php-wasm] Filter logs by severity in Logger and assign severity based on verbosity argument in CLI [php-wasm-logger] Filter logs by severity in Logger and assign severity based on verbosity argument in CLI Aug 18, 2025
@mho22 mho22 changed the title [php-wasm-logger] Filter logs by severity in Logger and assign severity based on verbosity argument in CLI [php-wasm-logger] Filter logs by severity in Logger and assign severity based on verbosity argument in CLIs Aug 18, 2025
@brandonpayton brandonpayton requested a review from a team August 20, 2025 17:48
Copy link
Member

@brandonpayton brandonpayton left a comment

Choose a reason for hiding this comment

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

@mho22, these changes look great to me. We've needed something like this for a while, and I think we'll be able to build on this to further improve/implement other code like the Playground CLI's --experimental-trace flag.

I left some questions and comments. Most of the comments simple "I like this" kinds of comments, but there are others too.

@brandonpayton
Copy link
Member

@mho22, if you believe this PR is complete and have no other concerns, please feel free to merge this.

@mho22
Copy link
Collaborator Author

mho22 commented Aug 26, 2025

I updated the code with your suggestions. The tests passed. I guess this can be merged.

@mho22 mho22 merged commit 54afa8a into trunk Aug 26, 2025
26 checks passed
@mho22 mho22 deleted the add-verbose-option-in-xdebug-bridge branch August 26, 2025 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants