mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
34 lines
896 B
TypeScript
34 lines
896 B
TypeScript
import util from 'util'
|
|
|
|
import { Decimal } from 'decimal.js-light'
|
|
|
|
export abstract class AbstractLoggingView {
|
|
protected bufferStringFormat: BufferEncoding = 'hex'
|
|
|
|
// This function gets called automatically when JSON.stringify() is called on this class instance
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
public abstract toJSON(): any
|
|
public toString(): string {
|
|
return JSON.stringify(this.toJSON(), null, 2)
|
|
}
|
|
|
|
// called form console.log or log4js logging functions
|
|
[util.inspect.custom](): string {
|
|
return this.toString()
|
|
}
|
|
|
|
public dateToString(date: Date | undefined | null): string | undefined {
|
|
if (date) {
|
|
return date.toISOString()
|
|
}
|
|
return undefined
|
|
}
|
|
|
|
public decimalToString(number: Decimal | undefined | null): string | undefined {
|
|
if (number) {
|
|
return number.toString()
|
|
}
|
|
return undefined
|
|
}
|
|
}
|