Skip to content

Commit

Permalink
support loglevel filter in playground (#3569)
Browse files Browse the repository at this point in the history
support loglevel filter in playground to avoid too many verbose log as
well as user can filter logs as needed.

fixes #3554
  • Loading branch information
RodgeFu authored Jun 12, 2024
1 parent 913aa03 commit 35e8625
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/playground-log-2024-5-12-13-33-41.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/playground"
---

Support loglevel in playground's logging
27 changes: 25 additions & 2 deletions packages/playground/src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
},
Expand Down

0 comments on commit 35e8625

Please sign in to comment.