Skip to content

Commit 54afa8a

Browse files
mho22adamziel
andauthored
[php-wasm-logger] Filter logs by severity in Logger and assign severity based on verbosity argument in CLIs (#2436)
## 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 : ```typescript 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 : ```typescript .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 : ```typescript 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 : ```typescript 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":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... ``` --------- Co-authored-by: Adam Zieliński <[email protected]>
1 parent ba3e7d7 commit 54afa8a

File tree

29 files changed

+759
-396
lines changed

29 files changed

+759
-396
lines changed

CHANGELOG.md

Lines changed: 94 additions & 109 deletions
Large diffs are not rendered by default.

packages/docs/site/docs/developers/05-local-development/04-wp-playground-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ The `server` command supports the following optional arguments:
112112
- `--login`: Automatically log the user in as an administrator.
113113
- `--skip-wordpress-setup`: Do not download or install WordPress. Useful if you are mounting a full WordPress directory.
114114
- `--skip-sqlite-setup`: Do not set up the SQLite database integration.
115-
- `--quiet`: Do not output logs and progress messages.
115+
- `--verbosity`: Output logs and progress messages. Choices are "quiet", "normal" or "debug". Defaults to "normal".
116116
- `--debug`: Print the PHP error log if an error occurs during boot.
117117

118118
## Need some help with the CLI?

packages/docs/site/docs/main/changelog.md

Lines changed: 94 additions & 109 deletions
Large diffs are not rendered by default.

packages/docs/site/i18n/gu/docusaurus-plugin-content-docs/current/main/contributing/contributor-badge.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ This page provides detailed information on the Playground Contributor Badge and
3030
Any contribution to the WordPress Playground project is highly valued. The Playground team recognizes contributions across several key areas:
3131
-->
3232

33-
- **પ્લેગ્રાઉન્ડ કોડ:** કોડમાં ફેરફાર કરવા અને મુખ્ય પ્રોજેક્ટની સમીક્ષા કરવી.
34-
- **પ્લેગ્રાઉન્ડ UI:** વેબ અનુભવના યુઝર ઇન્ટરફેસમાં સુધારો કરવો.
35-
- **દસ્તાવેજીકરણ:** દસ્તાવેજીકરણ લખવું, અપડેટ કરવું અને સમીક્ષા કરવી.
36-
- **અનુવાદ:** પ્રોજેક્ટના કોઈપણ ભાગનું ભાષાંતર કરવું.
37-
- **બ્લુપ્રિન્ટ્સ ગેલેરી:** નવી બ્લુપ્રિન્ટ્સ બનાવવી અથવા હાલના બ્લુપ્રિન્ટ્સને સુધારવું.
33+
- **પ્લેગ્રાઉન્ડ કોડ:** કોડમાં ફેરફાર કરવા અને મુખ્ય પ્રોજેક્ટની સમીક્ષા કરવી.
34+
- **પ્લેગ્રાઉન્ડ UI:** વેબ અનુભવના યુઝર ઇન્ટરફેસમાં સુધારો કરવો.
35+
- **દસ્તાવેજીકરણ:** દસ્તાવેજીકરણ લખવું, અપડેટ કરવું અને સમીક્ષા કરવી.
36+
- **અનુવાદ:** પ્રોજેક્ટના કોઈપણ ભાગનું ભાષાંતર કરવું.
37+
- **બ્લુપ્રિન્ટ્સ ગેલેરી:** નવી બ્લુપ્રિન્ટ્સ બનાવવી અથવા હાલના બ્લુપ્રિન્ટ્સને સુધારવું.
3838

3939
<!--
4040
- **Playground Code:** Making code changes and reviewing the core project.

packages/docs/site/i18n/gu/docusaurus-plugin-content-docs/current/main/contributing/index.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ WordPress Playground is an open-source project that welcomes contributors of all
2323
## How can I contribute?
2424
-->
2525

26-
- કોડ? [વિકાસકર્તા વિભાગ](/contributing/code) જુઓ.
27-
- દસ્તાવેજીકરણ? [દસ્તાવેજીકરણ વિભાગ](/contributing/documentation) જુઓ.
28-
- ભૂલોની જાણ કરવી? મુખ્ય GitHub રિપોઝીટરીમાં અથવા [પ્લેગ્રાઉન્ડ સાધનો](https://github.com/WordPress/playground-tools/issues/new) માં [નવો અંક](https://github.com/WordPress/wordpress-playground/issues/new) ખોલો.
29-
- વિચારો, ડિઝાઇન, અથવા બીજું કંઈ? [GitHub ચર્ચા](https://github.com/WordPress/wordpress-playground/discussions) ખોલો, અને ચાલો વાત કરીએ!
26+
- કોડ? [વિકાસકર્તા વિભાગ](/contributing/code) જુઓ.
27+
- દસ્તાવેજીકરણ? [દસ્તાવેજીકરણ વિભાગ](/contributing/documentation) જુઓ.
28+
- ભૂલોની જાણ કરવી? મુખ્ય GitHub રિપોઝીટરીમાં અથવા [પ્લેગ્રાઉન્ડ સાધનો](https://github.com/WordPress/playground-tools/issues/new) માં [નવો અંક](https://github.com/WordPress/wordpress-playground/issues/new) ખોલો.
29+
- વિચારો, ડિઝાઇન, અથવા બીજું કંઈ? [GitHub ચર્ચા](https://github.com/WordPress/wordpress-playground/discussions) ખોલો, અને ચાલો વાત કરીએ!
3030

3131
<!--
3232
- Code? See the [developer section](/contributing/code).
@@ -41,9 +41,9 @@ WordPress Playground is an open-source project that welcomes contributors of all
4141
## Guidelines
4242
-->
4343

44-
- બધા વર્ડપ્રેસ પ્રોજેક્ટ્સની જેમ, અમે દરેક માટે સ્વાગત અને આદરપૂર્ણ વાતાવરણ સુનિશ્ચિત કરવા માંગીએ છીએ. વધુ જાણવા માટે કૃપા કરીને અમારા સમુદાયની [આચારસંહિતા] (https://make.wordpress.org/handbook/community-code-of-conduct/) વાંચો.
45-
- કોડ ફાળો આપનારાઓએ [કોડિંગ સિદ્ધાંતો] (/contributing/coding-standards) ની સમીક્ષા કરવી જોઈએ.
46-
- તમે જે પણ યોગદાન આપો છો તેના પર તમે કૉપિરાઇટ જાળવી રાખો છો. પુલ રિક્વેસ્ટ સબમિટ કરીને, તમે [વર્ડપ્રેસ પ્લેગ્રાઉન્ડ લાઇસન્સ] (https://github.com/WordPress/wordpress-playground?tab=GPL-2.0-1-ov-file#readme) હેઠળ તે કોડ રિલીઝ કરવા માટે સંમત થાઓ છો.
44+
- બધા વર્ડપ્રેસ પ્રોજેક્ટ્સની જેમ, અમે દરેક માટે સ્વાગત અને આદરપૂર્ણ વાતાવરણ સુનિશ્ચિત કરવા માંગીએ છીએ. વધુ જાણવા માટે કૃપા કરીને અમારા સમુદાયની [આચારસંહિતા] (https://make.wordpress.org/handbook/community-code-of-conduct/) વાંચો.
45+
- કોડ ફાળો આપનારાઓએ [કોડિંગ સિદ્ધાંતો] (/contributing/coding-standards) ની સમીક્ષા કરવી જોઈએ.
46+
- તમે જે પણ યોગદાન આપો છો તેના પર તમે કૉપિરાઇટ જાળવી રાખો છો. પુલ રિક્વેસ્ટ સબમિટ કરીને, તમે [વર્ડપ્રેસ પ્લેગ્રાઉન્ડ લાઇસન્સ] (https://github.com/WordPress/wordpress-playground?tab=GPL-2.0-1-ov-file#readme) હેઠળ તે કોડ રિલીઝ કરવા માટે સંમત થાઓ છો.
4747

4848
<!--
4949
- As with all WordPress projects, we want to ensure a welcoming and respectful environment for everyone. Please read our community's [Code of Conduct](https://make.wordpress.org/handbook/community-code-of-conduct/) to learn more.
@@ -93,10 +93,10 @@ WordPress Playground and the WordPress project are strongly rooted in free and o
9393
As such, please be aware of the implications that your contributions will fall under:
9494
-->
9595

96-
- જ્યારે તમે યોગદાન આપો છો, ત્યારે તમે GPLv2 (અથવા પછીના) લાઇસન્સ હેઠળ તમારા યોગદાનને લાઇસન્સ આપવા માટે સંમત થાઓ છો.
97-
- GPL લાઇસન્સ મજબૂત કોપીલેફ્ટ જોગવાઈઓ ધરાવે છે જે ખાતરી કરે છે કે બધા ડેરિવેટિવ કાર્યો ઓપન-સોર્સ અને સમાન લાઇસન્સ શરતો હેઠળ રહે છે, જેનાથી સહયોગી વિકાસ વાતાવરણને પ્રોત્સાહન મળે છે.
98-
- GPL લાઇસન્સ કોઈપણ ફેરફારો, બગ ફિક્સેસ અથવા નવી સુવિધાઓને મૂળ કોડબેઝમાં પાછા આપવા માટે પ્રોત્સાહિત કરે છે.
99-
- GPL લાઇસન્સ ખાતરી કરે છે કે પ્રોજેક્ટ મફત અને ઓપન-સોર્સ રહે, માત્ર કિંમતની દ્રષ્ટિએ જ નહીં પરંતુ સોફ્ટવેરનો ઉપયોગ, ફેરફાર અને વિતરણ કરવાની સ્વતંત્રતાના સંદર્ભમાં પણ.
96+
- જ્યારે તમે યોગદાન આપો છો, ત્યારે તમે GPLv2 (અથવા પછીના) લાઇસન્સ હેઠળ તમારા યોગદાનને લાઇસન્સ આપવા માટે સંમત થાઓ છો.
97+
- GPL લાઇસન્સ મજબૂત કોપીલેફ્ટ જોગવાઈઓ ધરાવે છે જે ખાતરી કરે છે કે બધા ડેરિવેટિવ કાર્યો ઓપન-સોર્સ અને સમાન લાઇસન્સ શરતો હેઠળ રહે છે, જેનાથી સહયોગી વિકાસ વાતાવરણને પ્રોત્સાહન મળે છે.
98+
- GPL લાઇસન્સ કોઈપણ ફેરફારો, બગ ફિક્સેસ અથવા નવી સુવિધાઓને મૂળ કોડબેઝમાં પાછા આપવા માટે પ્રોત્સાહિત કરે છે.
99+
- GPL લાઇસન્સ ખાતરી કરે છે કે પ્રોજેક્ટ મફત અને ઓપન-સોર્સ રહે, માત્ર કિંમતની દ્રષ્ટિએ જ નહીં પરંતુ સોફ્ટવેરનો ઉપયોગ, ફેરફાર અને વિતરણ કરવાની સ્વતંત્રતાના સંદર્ભમાં પણ.
100100

101101
<!--
102102
- When you contribute, you agree to license your contributions under the GPLv2 (or later) license

packages/php-wasm/logger/project.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@
6464
"lintFilePatterns": ["packages/php-wasm/logger/**/*.ts"],
6565
"maxWarnings": 0
6666
}
67-
}
68-
},
69-
"typecheck": {
70-
"executor": "nx:run-commands",
71-
"options": {
72-
"commands": [
73-
"tsc -p packages/php-wasm/logger/tsconfig.lib.json --noEmit",
74-
"tsc -p packages/php-wasm/logger/tsconfig.spec.json --noEmit"
75-
]
67+
},
68+
"typecheck": {
69+
"executor": "nx:run-commands",
70+
"options": {
71+
"commands": [
72+
"tsc -p packages/php-wasm/logger/tsconfig.lib.json --noEmit",
73+
"tsc -p packages/php-wasm/logger/tsconfig.spec.json --noEmit"
74+
]
75+
}
7676
}
7777
}
7878
}

packages/php-wasm/logger/src/lib/collectors/collect-php-logs.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { UniversalPHP, PHPRequestErrorEvent } from '../types';
2-
import type { Logger } from '../logger';
2+
import { type Logger, LogPrefix, LogSeverity } from '../logger';
33

44
let lastPHPLogLength = 0;
55
export const errorLogPath = '/wordpress/wp-content/debug.log';
@@ -32,6 +32,7 @@ export const collectPhpLogs = (
3232
const currentLog = log.substring(lastPHPLogLength);
3333
loggerInstance.logMessage({
3434
message: currentLog,
35+
severity: LogSeverity.Log,
3536
raw: true,
3637
});
3738
lastPHPLogLength = log.length;
@@ -42,8 +43,9 @@ export const collectPhpLogs = (
4243
if (event.error) {
4344
loggerInstance.logMessage({
4445
message: `${event.error.message} ${event.error.stack}`,
45-
severity: 'Fatal',
46-
prefix: event.source === 'request' ? 'PHP' : 'WASM Crash',
46+
severity: LogSeverity.Fatal,
47+
prefix:
48+
event.source === 'request' ? LogPrefix.PHP : LogPrefix.WASM,
4749
});
4850
loggerInstance.dispatchEvent(
4951
new CustomEvent(loggerInstance.fatalErrorEvent, {

packages/php-wasm/logger/src/lib/collectors/collect-window-errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Logger } from '../logger';
1+
import { type Logger, LogSeverity } from '../logger';
22

33
/**
44
* Log Windows errors.
@@ -9,7 +9,7 @@ import type { Logger } from '../logger';
99
const logWindowErrorEvent = (loggerInstance: Logger, event: ErrorEvent) => {
1010
loggerInstance.logMessage({
1111
message: `${event.message} in ${event.filename} on line ${event.lineno}:${event.colno}`,
12-
severity: 'Error',
12+
severity: LogSeverity.Error,
1313
});
1414
};
1515

@@ -30,7 +30,7 @@ const logPromiseRejection = (
3030
const message = event?.reason.stack ?? event.reason;
3131
loggerInstance.logMessage({
3232
message,
33-
severity: 'Error',
33+
severity: LogSeverity.Error,
3434
});
3535
};
3636

packages/php-wasm/logger/src/lib/handlers/log-event.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { LogHandler } from '../log-handlers';
2-
import type { Log } from '../logger';
3-
import { logger } from '../logger';
2+
import { type Log, logger } from '../logger';
43

54
export const logEventType = 'playground-log';
65

packages/php-wasm/logger/src/lib/handlers/log-to-console.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { LogHandler } from '../log-handlers';
2-
import type { Log } from '../logger';
3-
import { prepareLogMessage } from '../logger';
2+
import { type Log, LogSeverity, prepareLogMessage } from '../logger';
43

54
/**
65
* Log message to the console.
@@ -23,19 +22,19 @@ export const logToConsole: LogHandler = (log: Log, ...args: any[]): void => {
2322
}
2423
/* eslint-disable no-console */
2524
switch (log.severity) {
26-
case 'Debug':
25+
case LogSeverity.Debug:
2726
console.debug(log.message, ...args);
2827
break;
29-
case 'Info':
28+
case LogSeverity.Info:
3029
console.info(log.message, ...args);
3130
break;
32-
case 'Warn':
31+
case LogSeverity.Warn:
3332
console.warn(log.message, ...args);
3433
break;
35-
case 'Error':
34+
case LogSeverity.Error:
3635
console.error(log.message, ...args);
3736
break;
38-
case 'Fatal':
37+
case LogSeverity.Fatal:
3938
console.error(log.message, ...args);
4039
break;
4140
default:

0 commit comments

Comments
 (0)