-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve logging and generator output. (#322)
* Make superseded by warning message more useful. Signed-off-by: dblock <[email protected]> * Display log level as a string. Signed-off-by: dblock <[email protected]> * Added command line tool tests for merger and linter. Signed-off-by: dblock <[email protected]> --------- Signed-off-by: dblock <[email protected]>
- Loading branch information
Showing
17 changed files
with
210 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
import { Logger, LogLevel } from '../src/Logger' | ||
|
||
describe('Logger', () => { | ||
let log: jest.Mock | ||
|
||
beforeEach(() => { | ||
log = console.log = jest.fn() | ||
}) | ||
|
||
afterEach(() => { | ||
log.mockClear() | ||
}) | ||
|
||
describe('at default log level', () => { | ||
const logger = new Logger() | ||
|
||
test('sets log level at warn', () => { | ||
expect(logger.level).toEqual(LogLevel.warn) | ||
}) | ||
|
||
test('does not log info level messages', () => { | ||
logger.log('log') | ||
logger.error('error') | ||
logger.warn('warn') | ||
logger.info('info') | ||
expect(log.mock.calls).toEqual([ | ||
['log'], | ||
['[ERROR] error'], | ||
['[WARNING] warn'] | ||
]) | ||
}) | ||
}) | ||
|
||
describe('at info log level', () => { | ||
const logger = new Logger(LogLevel.info) | ||
|
||
test('sets log level at info', () => { | ||
expect(logger.level).toEqual(LogLevel.info) | ||
}) | ||
|
||
test('logs all messages', () => { | ||
logger.log('log') | ||
logger.error('error') | ||
logger.warn('warn') | ||
logger.info('info') | ||
expect(log.mock.calls).toEqual([ | ||
['log'], | ||
['[ERROR] error'], | ||
['[WARNING] warn'], | ||
['[INFO] info'] | ||
]) | ||
}) | ||
}) | ||
|
||
describe('at warn log level', () => { | ||
const logger = new Logger(LogLevel.warn) | ||
|
||
test('sets log level at warn', () => { | ||
expect(logger.level).toEqual(LogLevel.warn) | ||
}) | ||
|
||
test('does not log info messages', () => { | ||
logger.log('log') | ||
logger.error('error') | ||
logger.warn('warn') | ||
logger.info('info') | ||
expect(log.mock.calls).toEqual([ | ||
['log'], | ||
['[ERROR] error'], | ||
['[WARNING] warn'] | ||
]) | ||
}) | ||
}) | ||
|
||
describe('at error log level', () => { | ||
const logger = new Logger(LogLevel.error) | ||
|
||
test('sets log level at error', () => { | ||
expect(logger.level).toEqual(LogLevel.error) | ||
}) | ||
|
||
test('does not log warn and info messages', () => { | ||
logger.log('log') | ||
logger.error('error') | ||
logger.warn('warn') | ||
logger.info('info') | ||
expect(log.mock.calls).toEqual([ | ||
['log'], | ||
['[ERROR] error'] | ||
]) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.