mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-17 02:48:31 -07:00
31 lines
988 B
JavaScript
31 lines
988 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(),
|
|
logOutput: jest.fn(),
|
|
add: (transport) => transports.push(transport),
|
|
addTransport: (transport) => transports.push(transport),
|
|
setLevel: (newLevel) => {level = newLevel},
|
|
getLevel: () => level,
|
|
setTransportsEnabled: (value) => {transportsEnabled = value},
|
|
};
|
|
|
|
jest.mock('../../lib/util/logger', () => (mock));
|
|
|
|
module.exports = {...mock};
|