mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-27 21:20:03 +00:00
feat: Add a settings option to log to console in json format (#25649)
Co-authored-by: Nerivec <62446222+Nerivec@users.noreply.github.com>
This commit is contained in:
co-authored by
Nerivec
parent
6f3524b251
commit
26ef565c8a
@@ -118,6 +118,7 @@ describe('Extension: Bridge', () => {
|
||||
log_level: 'info',
|
||||
log_namespaced_levels: {},
|
||||
log_output: ['console', 'file'],
|
||||
log_console_json: false,
|
||||
log_rotation: true,
|
||||
log_symlink_current: false,
|
||||
log_syslog: {},
|
||||
|
||||
@@ -397,4 +397,28 @@ describe('Logger', () => {
|
||||
expect(logSpy).toHaveBeenLastCalledWith('debug', `z2m:test: ${splatChars}`);
|
||||
expect(consoleWriteSpy.mock.calls[1][0]).toMatch(new RegExp(`^.*\tz2m:test: ${splatChars}`));
|
||||
});
|
||||
|
||||
it('Logs to console in JSON when configured', () => {
|
||||
settings.set(['advanced', 'log_console_json'], true);
|
||||
logger.init();
|
||||
|
||||
consoleWriteSpy.mockClear();
|
||||
logger.info(`Test JSON message`, 'z2m');
|
||||
|
||||
const outputJSON = JSON.parse(consoleWriteSpy.mock.calls[0][0]);
|
||||
expect(outputJSON).toStrictEqual({
|
||||
level: 'info',
|
||||
message: 'z2m: Test JSON message',
|
||||
timestamp: expect.any(String),
|
||||
});
|
||||
|
||||
settings.set(['advanced', 'log_console_json'], false);
|
||||
logger.init();
|
||||
|
||||
consoleWriteSpy.mockClear();
|
||||
logger.info(`Test JSON message`, 'z2m');
|
||||
|
||||
const outputStr: string = consoleWriteSpy.mock.calls[0][0];
|
||||
expect(outputStr.trim().endsWith('\u001b[32minfo\u001b[39m: \tz2m: Test JSON message')).toStrictEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user