Skip to content

Commit

Permalink
fix: Return a fallback log context if none is set rather than erroring
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmenzel committed Feb 6, 2025
1 parent 7731a7f commit 4440b93
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class LoggingContext {
run<R>(cb: () => R) {
return LoggingContext.asyncStore.run(this, cb)
}

private static fallbackContext = new LoggingContext()
private static asyncStore = new AsyncLocalStorage<LoggingContext>()

static create(): LoggingContext {
Expand All @@ -128,7 +128,7 @@ export class LoggingContext {
static get current() {
const ctx = this.asyncStore.getStore()
if (!ctx) {
throw new Error('There is no current context')
return this.fallbackContext
}
return ctx
}
Expand Down

0 comments on commit 4440b93

Please sign in to comment.