This commit is contained in:
Siddharth Singh 2025-04-06 15:33:36 +05:30
parent 82e7f854b9
commit d3a15a699e
No known key found for this signature in database

View file

@ -37,10 +37,10 @@ const prettyPrint = (msg: LogiValue): string => {
case 'undefined': case 'undefined':
return `<${type}>`; return `<${type}>`;
case 'object': case 'object':
if (message === null) return "<null>"; if (message === null) return '<null>';
return JSON.stringify(message, (_, v) => { return JSON.stringify(message, (_, v) => {
if (Array.isArray(v)) { if (Array.isArray(v)) {
return `[${v.map(itm => JSON.stringify(itm)).join(', ')}]`; return `[${v.map((itm) => JSON.stringify(itm)).join(', ')}]`;
} }
if (typeof v === 'string') return `\`${v}\``; if (typeof v === 'string') return `\`${v}\``;
return v; return v;
@ -49,11 +49,11 @@ const prettyPrint = (msg: LogiValue): string => {
.replace(/^"/, '') .replace(/^"/, '')
.replace(/"$/, ''); .replace(/"$/, '');
} }
} };
const pair = (key: string, value: LogiValue | undefined) => { const pair = (key: string, value: LogiValue | undefined) => {
return `${key} => ${prettyPrint(value || '')}` return `${key} => ${prettyPrint(value || '')}`;
} };
export const createLogiHandler = (conf: DittoConf, defaultHandler: LogiHandler) => (log: LogiLog) => { export const createLogiHandler = (conf: DittoConf, defaultHandler: LogiHandler) => (log: LogiLog) => {
const { fmt, level, scopes } = conf.logConfig; const { fmt, level, scopes } = conf.logConfig;
@ -65,7 +65,13 @@ export const createLogiHandler = (conf: DittoConf, defaultHandler: LogiHandler)
const remaining = Object.entries(log) const remaining = Object.entries(log)
.filter(([key]) => !['ns', 'level', 'message', 'msg'].includes(key)); .filter(([key]) => !['ns', 'level', 'message', 'msg'].includes(key));
console.group(`%c${log.level.toUpperCase()} %c${log.ns} %c${message || ''}`, `color: ${colors[log.level]}; font-weight: bold`, 'font-weight: normal; color: yellow', 'color: unset'); console.group(
console.log(remaining.map(itm => pair(...itm)).join('\n')); `%c${log.level.toUpperCase()} %c${log.ns} %c${message || ''}`,
`color: ${colors[log.level]}; font-weight: bold`,
'font-weight: normal; color: yellow',
'color: unset',
);
console.log(remaining.map((itm) => pair(...itm)).join('\n'));
console.groupEnd(); console.groupEnd();
}; };