Merge branch 'fix-logging-defaults' into 'main'

fix logging default config

See merge request soapbox-pub/ditto!735
This commit is contained in:
Siddharth Singh 2025-04-29 18:04:57 +00:00
commit 90540609f6
2 changed files with 10 additions and 3 deletions

View file

@ -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),
};

View file

@ -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));