extism / js-pdk

Write Extism plugins in JavaScript & TypeScript
BSD 3-Clause "New" or "Revised" License
56 stars 16 forks source link

feat: add info and debug logging to console global #68

Closed Phault closed 6 months ago

Phault commented 7 months ago

Noticed console.debug was missing, so figured I'd add it. It's also not obvious what log level console.log has, so I added console.info as well as an alias, which seems to match browser behaviour.

Diff looks a bit confusing, as I sorted the functions based on log level. 🤷

nilslice commented 7 months ago

Thanks, @Phault!

While we're in here, I wonder if it would be a good time to consider how we could support variadic args for the console functions.

For example, in JS, console.log takes any number of args and logs them, e.g.:

console.log("this", "is", "a", variable, 42, {a: 1}, [1, 2, variable, 3])

We only support using the first arg.

How close can we get these functions?

cc/ @bhelx

bhelx commented 6 months ago

Thanks for contributing! Let's merge this as is. I think it's a welcome addition. I'll create an issue for making these compatible with the w3c console.log, etc. I do think it might be easier to, instead of implementing some of these globals like console in rust, just expose the IO primitives from rust and implement it in JS in the polyfill layer. Open to different ideas on how to do it though.