Skip to content

Commit

Permalink
chore: Serialize object arguments in desktop runtime (#18359)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisamir98 authored Nov 26, 2024
1 parent 4135955 commit c93b3d0
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/script/util/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,42 @@
*
*/

import {LogFactory, Logger} from '@wireapp/commons';
import {LogFactory, Logger, Runtime} from '@wireapp/commons';

const LOGGER_NAMESPACE = '@wireapp/webapp';

function serializeArgs(args: any[]): any[] {
return args.map(arg => (typeof arg === 'object' && arg !== null ? JSON.stringify(arg) : arg));
}

function getLogger(name: string): Logger {
return LogFactory.getLogger(name, {
const logger = LogFactory.getLogger(name, {
namespace: LOGGER_NAMESPACE,
separator: '/',
});

if (Runtime.isDesktopApp()) {
return {
...logger,
debug: (...args: any[]): void => {
logger.debug(...serializeArgs(args));
},
error: (...args: any[]): void => {
logger.error(...serializeArgs(args));
},
info: (...args: any[]): void => {
logger.info(...serializeArgs(args));
},
log: (...args: any[]): void => {
logger.log(...serializeArgs(args));
},
warn: (...args: any[]): void => {
logger.warn(...serializeArgs(args));
},
};
}

return logger;
}

export {getLogger, LOGGER_NAMESPACE, Logger};

0 comments on commit c93b3d0

Please sign in to comment.