Built-in text formatters should be configurable
Closed this issue ยท 4 comments
ryuapp commented
I think this opinion is just a preference. Log levels are easier to understand with formal names.
DBG -> DEBUG
INF -> INFO
WRN -> WARNING
ERR -> ERROR
FTL -> FATAL
Is it possible to provide an option that does not use abbreviations?
dahlia commented
You can customize the text formatter of the sinks. However, it's not easy to just change the labels for log levels. The current workaround is like:
const sink = getConsoleSink({
formatter(record: string) {
const ts = new Date(record.timestamp);
let msg = "";
for (let i = 0; i < record.message.length; i++) {
if (i % 2 === 0) msg += record.message[i];
else msg += inspect(record.message[i]);
}
const category = record.category.join("\xb7");
return `${ts.toISOString().replace("T", " ").replace("Z", " +00:00")} [${
record.level.toUpperCase()
}] ${category}: ${msg}\n`;
},
});
I'm giving the default text formatter more flexibility in the next release, e.g.:
const sink = getConsoleSink({
formatter: getDefaultFormatter({
logLevel(level: LogLevel) {
return level.toUpperCase();
}
}),
});
ryuapp commented
Your suggestion meets my requirements. I look forward to the next release.
Thank you.
dahlia commented
You can now customize each part of log messages. It's available for preview in v0.6.0-dev.74+f4e8f8e6 (JSR & npm).