mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-17 10:58:31 -07:00
29 lines
901 B
JavaScript
29 lines
901 B
JavaScript
let level = 'info';
|
|
|
|
const transports = [];
|
|
|
|
let transportsEnabled = false;
|
|
const callTransports = (level, message) => {
|
|
if (transportsEnabled) {
|
|
for (const transport of transports) {
|
|
transport.log({level, message}, () => {});
|
|
}
|
|
}
|
|
}
|
|
|
|
const mock = {
|
|
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)),
|
|
cleanup: jest.fn(),
|
|
add: (transport) => transports.push(transport),
|
|
setLevel: (newLevel) => {level = newLevel},
|
|
getLevel: () => level,
|
|
setTransportsEnabled: (value) => {transportsEnabled = value},
|
|
};
|
|
|
|
jest.mock('../../lib/util/logger', () => (mock));
|
|
|
|
module.exports = {...mock};
|