mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-15 15:44:45 -04: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 {
|
export class ConsoleLoggerService implements LoggerService {
|
||||||
private classContext: string | undefined;
|
private classContext: string | undefined;
|
||||||
private lastTimestamp: number;
|
private lastTimestamp: number;
|
||||||
|
private skipColor = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(appConfiguration.KEY)
|
@Inject(appConfiguration.KEY)
|
||||||
|
@ -36,6 +37,10 @@ export class ConsoleLoggerService implements LoggerService {
|
||||||
this.classContext = context;
|
this.classContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setSkipColor(skipColor: boolean): void {
|
||||||
|
this.skipColor = skipColor;
|
||||||
|
}
|
||||||
|
|
||||||
error(message: unknown, trace = '', functionContext?: string): void {
|
error(message: unknown, trace = '', functionContext?: string): void {
|
||||||
this.printMessage(
|
this.printMessage(
|
||||||
message,
|
message,
|
||||||
|
@ -118,12 +123,22 @@ export class ConsoleLoggerService implements LoggerService {
|
||||||
isTimeDiffEnabled?: boolean,
|
isTimeDiffEnabled?: boolean,
|
||||||
): void {
|
): void {
|
||||||
let output;
|
let output;
|
||||||
if (isObject(message)) {
|
|
||||||
output = `${color('Object:')}\n${ConsoleLoggerService.sanitize(
|
// if skipColor is set, we do not use colors and skip sanitizing
|
||||||
JSON.stringify(message, null, 2),
|
if (this.skipColor) {
|
||||||
)}\n`;
|
if (isObject(message)) {
|
||||||
|
output = `${color('Object:')}\n${JSON.stringify(message, null, 2)}\n`;
|
||||||
|
} else {
|
||||||
|
output = message as string;
|
||||||
|
}
|
||||||
} else {
|
} 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 = {
|
const localeStringOptions: DateTimeFormatOptions = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue