wordpress-playground icon indicating copy to clipboard operation
wordpress-playground copied to clipboard

Use @php-wasm/logger for all logs

Open bgrgicak opened this issue 1 year ago • 3 comments

Now that error reporting is live, we could take some extra time to improve what data is logged and how it's being displayed.

Most logs currently use JS console.... for logging so we can't control if logs should be displayed and don't record these messages in the logger.

I suggest that we centralize all logs in the @php-wasm/logger, either by replacing console.... with a custom function, or by overriding console.... in the logger.

All logs would be recorded by the logger and we would be able to use them for error reporting and debugging.

To display logs, we could add a new query API param like debug=yes to print these logs using JS console.

Additionally, we could store logs in a global variable so they are accessible through the JS console, or create a modal that displays all log messages. This would allow users to view logs if they didn't set debug=yes.

bgrgicak avatar Mar 27 '24 09:03 bgrgicak

+1 to that. It would be also neat to have logging levels in the logger, like console.warn(), instead of just a yes/no switch. Then we could map those logger calls to specific console.* calls and use the devtools filtering.

adamziel avatar Mar 28 '24 15:03 adamziel

+1 to that. It would be also neat to have logging levels in the logger, like console.warn(), instead of just a yes/no switch.

I would definitely like to use log levels, but I think it's also important to allow users to disable log outputs to the console to reduce the noise from Playground while still seeing their logs.

bgrgicak avatar Mar 29 '24 05:03 bgrgicak

Possibly relevant

  • #1164

(helpful for novice users who want to report errors but don't know how to use the console)

flexseth avatar Mar 31 '24 01:03 flexseth