Skip to content

Commit

Permalink
fix(logSettings): actually allow more levels than "warn" and "error"
Browse files Browse the repository at this point in the history
"loglevel" is self-modifying, requiring getter functions to get the correct function at the time.
  • Loading branch information
hasezoey committed Feb 8, 2025
1 parent 3dec543 commit db321bd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/logSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import * as _logger from 'loglevel';

// this has to be re-defined as otherwise jest is not able to mock any function
// when "esModuleInterop: true" and "_logger" is not default imported
// and "_logger" cannot be default imported as that would make all projects using auto-increment require to set "allowSyntheticDefaultImports"
// and "_logger" cannot be default imported as that would make all projects using typegoose require to set "allowSyntheticDefaultImports"
export const logger = {
warn: _logger.warn,
error: _logger.error,
info: _logger.info,
debug: _logger.debug,
// "loglevel" here referred as "_logger" is self-modifying, so a getter function is necessary to actually get logs
// otherwise we only get the default "noop" function forever
warn: (...args) => _logger.warn.apply(undefined, args),
error: (...args) => _logger.error.apply(undefined, args),
info: (...args) => _logger.info.apply(undefined, args),
debug: (...args) => _logger.debug.apply(undefined, args),
setLogLevel: _logger.setLevel,
LogLevels: _logger.levels,
setDefaultLevel: _logger.setDefaultLevel,
Expand Down

0 comments on commit db321bd

Please sign in to comment.