This is a workaround rather than exact solution
I ended up creating a logger that wraps an outputchannel
and writes to it
import * as vscode from 'vscode';
import * as util from 'util' // has no default export
import { OutputChannel } from "vscode";
export class Logger {
private outputChannel:OutputChannel ;
constructor(extensionOuputName: string, private useConsole = true) {
if (!useConsole) {
this.outputChannel = vscode.window.createOutputChannel(extensionOuputName);
this.outputChannel.show();
}
}
public append(o: any) {
const prefix = `[${new Date().toLocaleString()}]`;
if (o.constructor === Array) {
o.forEach(item => this.append(item));
}
else {
if (this.useConsole) {
console.log(prefix, o);
}
else {
this.outputChannel.append(prefix + ' ');
const isObject = (typeof o === 'object' && o !== null);
//be carefull stringify can not convert circular dependencies
//this.outputChannel.appendLine(isObject ? JSON.stringify(o) : o);
this.outputChannel.appendLine(isObject ? util.inspect(o) : o);
}
}
}
}
Then in your extension just create a logger and use it
export class YourClass {
//false to use the outputchannel - true to use regular console
private log: Logger = new Logger('Nav-Code', false);
this.log.append(`Checking folder: ${this.projectFolder}`);
This creates and shows an outputchannel
with the name 'Nav-Code'
