sg-wireless / pymakr-vsc

GNU General Public License v3.0
97 stars 25 forks source link

use the vscode output channel for pymakr logs - vNext #213

Closed Josverl closed 2 years ago

Josverl commented 2 years ago

Feature Request 🚀

Is your feature request related to a problem? Please describe.

to report/troubleshoot problem end-users are directed to the developer debug logs in vscode.

While this works for experienced users, these are not intended to be used by end-users, and there is oven a lot of other information shown, that has little relevance to Pymakr.

Also it is not so discoverable for end users. (by design)

better yet, there is functionality in vscode that can be accessed with just a few lines of code

Describe the solution you'd like

something like :

const createLogger = (name) => {
  //Create output channel
  let outputChannel = vscode.window.createOutputChannel("PyMakr");
  //Write to output.
  outputChannel.appendLine("this is your user friendly logger.");

  const log = _createLogger(
    {
      methods: {
        debugShort: console.log,
        traceShort: console.log,
        info: outputChannel.appendLine, // :-( does not work this simple

      },
    },
    name
  );

However I could not find how to persuade consolite to call outputChannel.appendLine rather than console.log

Teachability, Documentation, Adoption, Migration Strategy

image

jakobrosenberg commented 2 years ago

Thanks!! I've been looking for that.

You would need to bind the method for it to work

info: outputChannel.appendLine.bind(outputChannel)

or you could do this

info: (...params) => outputChannel.appendLine(...params)

The reason it works for console.log is that the custom methods get mounted in an object that's already bound to console.

Josverl commented 2 years ago

binding seems to work , but still it does not appear to be called /integrated by consolite, and im not sure how to trace/debug that (see above PR)

I think the 2nd example may be typescript , at least that is what code thinks :-)

jakobrosenberg commented 2 years ago

My bad. I had accidentally written a : instead of a =>. 😅

jakobrosenberg commented 2 years ago

I found the issue. appendLine only accepts a single string, while console[method] supports a variadic input of any type. The solutions was

https://github.com/pycom/pymakr-vsc/commit/4b4b8a1015234fe6509674193decdd7169d7d788#diff-2ec4d3a277ed3e946eafeaa0ad4a72485817306f3afbf294a3d0d34adfd3e947R16-R19

I have merged your PR with the changes into next-staging.