-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
configurable log levels per logger instance
- Loading branch information
Showing
2 changed files
with
65 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
// set axiom env vars before importing logger | ||
process.env.AXIOM_INGEST_ENDPOINT = 'https://example.co/api/test'; | ||
process.env.AXIOM_LOG_LEVEL = 'error'; | ||
import { log, Logger } from '../src/logger'; | ||
|
||
jest.useFakeTimers(); | ||
|
||
test('log levels', async () => { | ||
global.fetch = jest.fn() as jest.Mock; | ||
|
||
log.info('test'); | ||
await log.flush(); | ||
expect(fetch).toHaveBeenCalledTimes(0); | ||
|
||
// test overriding log level per logger | ||
let logger = new Logger({}, null, false, 'frontend', 'error'); | ||
logger.debug('hello'); | ||
logger.info('hello'); | ||
logger.warn('hello'); | ||
await logger.flush(); | ||
expect(fetch).toHaveBeenCalledTimes(0); | ||
|
||
logger = new Logger({}, null, false, 'frontend', 'warn'); | ||
logger.info('hello'); | ||
logger.debug('hello'); | ||
await logger.flush(); | ||
expect(fetch).toHaveBeenCalledTimes(0); | ||
|
||
logger = new Logger({}, null, false, 'frontend', 'info'); | ||
logger.debug('hello'); | ||
await logger.flush(); | ||
expect(fetch).toHaveBeenCalledTimes(0); | ||
|
||
logger = new Logger({}, null, false, 'frontend', 'error'); | ||
logger.warn('warn'); | ||
logger.error('error'); | ||
await logger.flush(); | ||
expect(fetch).toHaveBeenCalledTimes(1); | ||
|
||
logger = new Logger({}, null, false, 'frontend', 'debug'); | ||
logger.warn('hello'); | ||
await logger.flush(); | ||
expect(fetch).toHaveBeenCalledTimes(2); | ||
}); |
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