Use @php-wasm/logger for all logs
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.
+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.
+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.
Possibly relevant
- #1164
(helpful for novice users who want to report errors but don't know how to use the console)