mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-04-14 12:05:10 +00:00
feat(console-logger): allow to bring own colors
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
b670702f41
commit
d3c6deffb4
1 changed files with 20 additions and 5 deletions
|
@ -23,6 +23,7 @@ import DateTimeFormatOptions = Intl.DateTimeFormatOptions;
|
|||
export class ConsoleLoggerService implements LoggerService {
|
||||
private classContext: string | undefined;
|
||||
private lastTimestamp: number;
|
||||
private skipColor = false;
|
||||
|
||||
constructor(
|
||||
@Inject(appConfiguration.KEY)
|
||||
|
@ -36,6 +37,10 @@ export class ConsoleLoggerService implements LoggerService {
|
|||
this.classContext = context;
|
||||
}
|
||||
|
||||
setSkipColor(skipColor: boolean): void {
|
||||
this.skipColor = skipColor;
|
||||
}
|
||||
|
||||
error(message: unknown, trace = '', functionContext?: string): void {
|
||||
this.printMessage(
|
||||
message,
|
||||
|
@ -118,12 +123,22 @@ export class ConsoleLoggerService implements LoggerService {
|
|||
isTimeDiffEnabled?: boolean,
|
||||
): void {
|
||||
let output;
|
||||
if (isObject(message)) {
|
||||
output = `${color('Object:')}\n${ConsoleLoggerService.sanitize(
|
||||
JSON.stringify(message, null, 2),
|
||||
)}\n`;
|
||||
|
||||
// if skipColor is set, we do not use colors and skip sanitizing
|
||||
if (this.skipColor) {
|
||||
if (isObject(message)) {
|
||||
output = `${color('Object:')}\n${JSON.stringify(message, null, 2)}\n`;
|
||||
} else {
|
||||
output = message as string;
|
||||
}
|
||||
} else {
|
||||
output = color(ConsoleLoggerService.sanitize(message as string));
|
||||
if (isObject(message)) {
|
||||
output = `${color('Object:')}\n${ConsoleLoggerService.sanitize(
|
||||
JSON.stringify(message, null, 2),
|
||||
)}\n`;
|
||||
} else {
|
||||
output = color(ConsoleLoggerService.sanitize(message as string));
|
||||
}
|
||||
}
|
||||
|
||||
const localeStringOptions: DateTimeFormatOptions = {
|
||||
|
|
Loading…
Add table
Reference in a new issue