2020-03-29 13:43:52 +00:00
|
|
|
import { ConsoleLogger, Logger, NullLogger } from 'noicejs';
|
2020-03-31 13:29:47 +00:00
|
|
|
import { isDebug } from './Env';
|
2020-03-29 13:43:52 +00:00
|
|
|
|
2020-03-31 13:49:18 +00:00
|
|
|
/**
|
|
|
|
* Get a test logger. Returns a null logger unless `verbose` is true or run under debug mode.
|
|
|
|
*/
|
2020-03-29 13:43:52 +00:00
|
|
|
export function getTestLogger(verbose = false): Logger {
|
2020-03-30 23:23:53 +00:00
|
|
|
if (verbose || isDebug()) {
|
|
|
|
return ConsoleLogger.global;
|
2020-03-29 13:43:52 +00:00
|
|
|
} else {
|
2020-03-30 23:23:53 +00:00
|
|
|
return NullLogger.global;
|
2020-03-29 13:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 13:49:18 +00:00
|
|
|
/**
|
|
|
|
* Create a spy logger using the provided methods, which returns itself as a child.
|
2021-08-08 00:34:19 +00:00
|
|
|
*
|
|
|
|
* @todo ensure all methods are present by extending null logger
|
2020-03-31 13:49:18 +00:00
|
|
|
*/
|
2020-03-29 13:43:52 +00:00
|
|
|
export function spyLogger(spies: Partial<Logger>): Logger {
|
|
|
|
const logger = {
|
|
|
|
...spies,
|
|
|
|
child: () => logger,
|
|
|
|
} as Logger;
|
2021-08-08 00:34:19 +00:00
|
|
|
|
2020-03-29 13:43:52 +00:00
|
|
|
return logger;
|
|
|
|
}
|