1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-03 23:50:33 +02:00

Chore: All: Change Logger to accept formatter function (#8702)

This commit is contained in:
pedr
2023-08-28 10:30:56 -03:00
committed by GitHub
parent 9430dccb61
commit ddc74af3d1
2 changed files with 9 additions and 8 deletions

View File

@ -18,6 +18,8 @@ export enum LogLevel {
Debug = 40,
}
type FormatFunction = (level: LogLevel, targetPrefix?: string)=> string;
interface TargetOptions {
level?: LogLevel;
database?: any;
@ -27,10 +29,7 @@ interface TargetOptions {
source?: string;
// Default message format
format?: string;
// If specified, will use this as format if it's an info message
formatInfo?: string;
format?: string | FormatFunction;
}
interface Target extends TargetOptions {
@ -228,7 +227,7 @@ class Logger {
let items: any[] = [];
if (target.format) {
const format = level === LogLevel.Info && target.formatInfo ? target.formatInfo : target.format;
const format = typeof target.format === 'string' ? target.format : target.format(level, targetPrefix);
const s = sprintf(format, {
date_time: moment().format('YYYY-MM-DD HH:mm:ss'),