Skip to content

Commit

Permalink
Use specified log level
Browse files Browse the repository at this point in the history
  • Loading branch information
satazor authored and Americas committed Nov 20, 2023
1 parent b17984e commit a72e85e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = function debugnyan(name, options, { prefix = 'sub', simple = tr
}

if (debug.enabled(name)) {
loggers[name].level(bunyan.DEBUG);
loggers[name].level(options?.level ?? bunyan.DEBUG);
}

return loggers[name];
Expand Down
10 changes: 9 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ describe('debugnyan', () => {
expect(logger.fields.name).toEqual('nor');
});

it('should be on the debug level if `DEBUG` matches logger name', () => {
it('should be on the default debug level if `DEBUG` matches logger name', () => {
debug.enable('abc');

const logger = debugnyan('abc');

expect(logger.level()).toEqual(Logger.DEBUG);
});

it('should be on the specified level if `DEBUG` matches logger name', () => {
debug.enable('abc');

const logger = debugnyan('abc', { level: 'warn' });

expect(logger.level()).toEqual(Logger.WARN);
});

describe('namespacing', () => {
it('should support multiple components separated by colons', () => {
const logger = debugnyan('foo:bar:biz:qux');
Expand Down

0 comments on commit a72e85e

Please sign in to comment.