diff --git a/.chronus/changes/playground-log-2024-5-12-13-33-41.md b/.chronus/changes/playground-log-2024-5-12-13-33-41.md new file mode 100644 index 0000000000..31f06a636a --- /dev/null +++ b/.chronus/changes/playground-log-2024-5-12-13-33-41.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@typespec/playground" +--- + +Support loglevel in playground's logging \ No newline at end of file diff --git a/packages/playground/src/services.ts b/packages/playground/src/services.ts index 1d592d5b2a..f35c019f83 100644 --- a/packages/playground/src/services.ts +++ b/packages/playground/src/services.ts @@ -55,8 +55,31 @@ export async function registerMonacoLanguage(host: BrowserHost) { return model ? textDocumentForModel(model) : undefined; }, sendDiagnostics() {}, - // eslint-disable-next-line no-console - log: console.log, + log: (log) => { + switch (log.level) { + case "error": + // eslint-disable-next-line no-console + console.error(log); + break; + case "warning": + // eslint-disable-next-line no-console + console.warn(log); + break; + case "info": + // eslint-disable-next-line no-console + console.info(log); + break; + case "debug": + // corresponding to Verbose LogLevel in Edge/Chrome which is off by default + // eslint-disable-next-line no-console + console.debug(log); + break; + case "trace": + default: + // just skip traces in playground + break; + } + }, applyEdit(param) { return Promise.resolve({ applied: false }); },