I am writing an extension for Visual Studio Code and I would like to receive logs from users if they click a button.
Currently I made a wrapper around console.log like this :
import * as path from 'path';
export const logger = (baseName: string) => {
if (process.env.NODE_ENV !== "dev") return () => { };
baseName = path.basename(baseName).toUpperCase().toString()
return (...params: any[]) => {
// 1. Convert args to a normal array
var args = Array.prototype.slice.call(params);
// 2. Prepend log prefix log string
args.unshift(baseName + ": ");
console.log.apply(console, args);
}
};
It works fine for output that I create myself, so I could store it in some array. However this doesn't account for error, which is very important to debug and reproduce the issue.
I've checked solutions from here, but due to the extension sandboxing and/or the fact this is nodejs (so window is not defined here) I was not able to use them.