2019-09-25 01:55:50 -07:00
|
|
|
let level = 'info';
|
|
|
|
|
2020-07-28 13:12:22 -07:00
|
|
|
const transports = [];
|
|
|
|
|
|
|
|
let transportsEnabled = false;
|
|
|
|
const callTransports = (level, message) => {
|
|
|
|
if (transportsEnabled) {
|
|
|
|
for (const transport of transports) {
|
|
|
|
transport.log({level, message}, () => {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 10:48:09 -07:00
|
|
|
const mock = {
|
2020-07-28 13:12:22 -07:00
|
|
|
info: jest.fn().mockImplementation((msg) => callTransports('info', msg)),
|
|
|
|
warn: jest.fn().mockImplementation((msg) => callTransports('warn', msg)),
|
|
|
|
error: jest.fn().mockImplementation((msg) => callTransports('error', msg)),
|
|
|
|
debug: jest.fn().mockImplementation((msg) => callTransports('debug', msg)),
|
2019-09-09 10:48:09 -07:00
|
|
|
cleanup: jest.fn(),
|
2020-07-28 13:12:22 -07:00
|
|
|
add: (transport) => transports.push(transport),
|
2019-09-25 01:55:50 -07:00
|
|
|
setLevel: (newLevel) => {level = newLevel},
|
|
|
|
getLevel: () => level,
|
2020-07-28 13:12:22 -07:00
|
|
|
setTransportsEnabled: (value) => {transportsEnabled = value},
|
2019-09-09 10:48:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
jest.mock('../../lib/util/logger', () => (mock));
|
|
|
|
|
|
|
|
module.exports = {...mock};
|