From 35e8625014e468bd7079a2c53e4b45b1d17c39e0 Mon Sep 17 00:00:00 2001 From: Rodge Fu Date: Wed, 12 Jun 2024 22:54:50 +0800 Subject: [PATCH] support loglevel filter in playground (#3569) support loglevel filter in playground to avoid too many verbose log as well as user can filter logs as needed. fixes #3554 --- .../playground-log-2024-5-12-13-33-41.md | 7 +++++ packages/playground/src/services.ts | 27 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 .chronus/changes/playground-log-2024-5-12-13-33-41.md 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 }); },