Skip to content

Commit

Permalink
Add json formatter configuration to the logger
Browse files Browse the repository at this point in the history
  • Loading branch information
stirante committed Dec 5, 2023
1 parent c435af2 commit 6064667
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,20 @@ function starMatch(pattern: string, str: string): boolean {
return pattern === str
}

const loggingSettings: {
filter: string[];
level: LogLevel;
type LoggingSettings = {
filter: string[],
level: LogLevel,
formatFunction: (level: LogLevel, logger: Logger, message: string) => string
} = {
jsonFormatter: ColorJSON
}

const loggingSettings:LoggingSettings = {
level: LogLevel.Info,
filter: ['*'],
formatFunction: (level: LogLevel, logger: Logger, message: string) => {
return `[${level}][${ChatColor.MATERIAL_EMERALD}${logger.name}${ChatColor.RESET}] ${message}`
}
},
jsonFormatter: ColorJSON.DEFAULT
}

/**
Expand Down Expand Up @@ -160,6 +164,13 @@ export class Logger {
loggingSettings.formatFunction = func;
}
/**
* Set the JSON formatter for the logger.
* @param {ColorJSON} formatter - The json formatter to set.
*/
static setJsonFormatter(formatter: ColorJSON) {
loggingSettings.jsonFormatter = formatter;
}
/**
* Returns a new Logger.
*
* @param {string} name - The name of the Logger.
Expand Down

0 comments on commit 6064667

Please sign in to comment.