mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'fix-logging-defaults' into 'main'
fix logging default config See merge request soapbox-pub/ditto!735
This commit is contained in:
commit
90540609f6
2 changed files with 10 additions and 3 deletions
|
|
@ -250,9 +250,15 @@ export class DittoConf {
|
||||||
level: string;
|
level: string;
|
||||||
scopes: 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 {
|
return {
|
||||||
fmt: fmt === 'jsonl' ? fmt : 'pretty',
|
fmt: fmt as 'jsonl' | 'pretty',
|
||||||
level,
|
level,
|
||||||
scopes: scopes.split(',').filter(Boolean),
|
scopes: scopes.split(',').filter(Boolean),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -57,10 +57,11 @@ const pair = (key: string, value: LogiValue | undefined) => {
|
||||||
|
|
||||||
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;
|
||||||
if (fmt === 'jsonl') return defaultHandler(log);
|
|
||||||
if (!isLevel(level)) throw new Error(`Invalid log level ${level} specified`);
|
if (!isLevel(level)) throw new Error(`Invalid log level ${level} specified`);
|
||||||
if (!lowerLevels[level].includes(log.level)) return;
|
if (!lowerLevels[level].includes(log.level)) return;
|
||||||
if (scopes.length && !scopes.some((scope) => scope.startsWith(log.ns))) 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 message = prettyPrint(log.message || log.msg || '');
|
||||||
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));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue