fix: compatibility with log aggregators

This commit is contained in:
Rainer Killinger
2022-11-01 18:35:26 +01:00
parent 107d94d499
commit 8aef5b8d5b
8 changed files with 54 additions and 26 deletions

View File

@@ -14,21 +14,15 @@
*/
import {LogLevel} from '../logger';
import {Transformation} from '../transformation';
import moment from 'moment';
/**
* Transformation that adds a timestamp to output
*/
export class Timestamp implements Transformation {
/**
* Instantiate a new timestamp transformation
*
* @see https://momentjs.com/docs/#/displaying/format/
* @param format Format for timestamps
* Keep this transformation in production environments
*/
constructor(private readonly format = 'LLLL') {
// noop
}
useInProduction = true;
/**
* Add timestamp to output
@@ -37,8 +31,6 @@ export class Timestamp implements Transformation {
* @param output Output to add timestamp to
*/
transform(_logLevel: LogLevel, output: string): string {
const now = moment();
return `[${now.format(this.format)}] ${output}`;
return `[${new Date().toISOString()}] ${output}`;
}
}