diff --git a/packages/conf/DittoConf.ts b/packages/conf/DittoConf.ts index 1420bdf5..05e7d19f 100644 --- a/packages/conf/DittoConf.ts +++ b/packages/conf/DittoConf.ts @@ -250,9 +250,15 @@ export class DittoConf { level: string; scopes: string[]; } { - const [fmt = 'jsonl', level = 'debug', scopes = ''] = (this.env.get('LOG_CONFIG') || '').split(':').filter(Boolean); + let [fmt, level, scopes] = (this.env.get('LOG_CONFIG') || '').split(':'); + fmt ||= 'jsonl'; + level ||= 'debug'; + scopes ||= ''; + + if (fmt !== 'jsonl' && fmt !== 'pretty') fmt = 'jsonl'; + return { - fmt: fmt === 'jsonl' ? fmt : 'pretty', + fmt: fmt as 'jsonl' | 'pretty', level, scopes: scopes.split(',').filter(Boolean), }; diff --git a/packages/ditto/utils/logi.ts b/packages/ditto/utils/logi.ts index 4b764201..67217c7f 100644 --- a/packages/ditto/utils/logi.ts +++ b/packages/ditto/utils/logi.ts @@ -57,10 +57,11 @@ const pair = (key: string, value: LogiValue | undefined) => { export const createLogiHandler = (conf: DittoConf, defaultHandler: LogiHandler) => (log: LogiLog) => { const { fmt, level, scopes } = conf.logConfig; - if (fmt === 'jsonl') return defaultHandler(log); if (!isLevel(level)) throw new Error(`Invalid log level ${level} specified`); if (!lowerLevels[level].includes(log.level)) return; if (scopes.length && !scopes.some((scope) => scope.startsWith(log.ns))) return; + if (fmt === 'jsonl') return defaultHandler(log); + const message = prettyPrint(log.message || log.msg || ''); const remaining = Object.entries(log) .filter(([key]) => !['ns', 'level', 'message', 'msg'].includes(key));