Skip to content

Feature Request: API to check if a loglevel is enabled. #129

@brainkim

Description

@brainkim

LogTape provides excellent lazy evaluation for avoiding expensive computations:

logger.debug("Result: {value}", () => ({ value: expensive() }));

However, this only works for synchronous operations. For async operations, there's no way to avoid the computation:

// This always runs expensiveAsync(), even if debug is disabled
const result = await expensiveAsync();
logger.debug("Result: {result}", { result });

Proposed

Add an isEnabled(level) method to the Logger interface:

if (logger.isEnabled("debug")) {
  const result = await expensiveAsync();
  logger.debug("Result: {result}", { result });
}

Alternatively, maybe the callback API could accept async functions?

Use case

Currently I want to query logtape to determine if I should run expensive analysis (like ESBuild’s analyzeMetafile()) only when debug logging is enabled.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions