Skip to content

Commit

Permalink
feat(logging): Allow isDebugEnabled to be returned
Browse files Browse the repository at this point in the history
This will allow for debug checks to be ran prior to expensive logging
statements being crafted.

This contains no breaking changes and should resolve issue
[#41](#41)
  • Loading branch information
Deterus committed Jan 9, 2018
1 parent 300e74f commit 9e7d571
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,11 @@ export class Logger {
setLevel(level: number): void {
this.level = level;
}

/**
* Returns if the logger is in debug mode or not.
*/
isDebugEnabled(): boolean {
return this.level === logLevel.debug;
}
}
11 changes: 11 additions & 0 deletions test/logging.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ describe('The log manager ', () => {
expect(globalLogLevel).toEqual( LogManager.logLevel.debug);
});

it('should be able to tell if the log level is debug', () => {
LogManager.setLevel(LogManager.logLevel.debug);
var isDebugEnabledAtDebugLevel = logger.isDebugEnabled();

LogManager.setLevel(LogManager.logLevel.warn);
var isDebugEnabledAtWarnLevel = logger.isDebugEnabled();

expect(isDebugEnabledAtDebugLevel).toEqual(true);
expect(isDebugEnabledAtWarnLevel).toEqual(false);
});

describe('setting logLevel per individual logger instance', () =>
{
it('should not log if specific logger logLevel is none', () => {
Expand Down

0 comments on commit 9e7d571

Please sign in to comment.