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:
Jens-Uwe Mager
2025-01-08 19:22:26 +00:00
committed by GitHub
co-authored by Nerivec
parent 6f3524b251
commit 26ef565c8a
6 changed files with 43 additions and 7 deletions
+1
View File
@@ -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: {},
+24
View File
@@ -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);
});
});