import moment from 'moment-timezone' ; import { merge } from 'lodash' ; import { schema } from '@osd/config-schema' ; import { LogRecord , Layout } from '@osd/logging' ; const { literal , object } = schema ; const jsonLayoutSchema = object ( { kind : literal ( 'json' ) , } ) ; internal export interface JsonLayoutConfigType { kind : 'json' ; } internal export class JsonLayout implements Layout { public static configSchema = jsonLayoutSchema ; private static errorToSerializableObject ( error ) { if ( error === undefined ) { return error ; } return { message : error . message , type : error . name , stack_trace : error . stack , } ; } public format ( record ) { return JSON . stringify ( merge ( { '@timestamp' : moment ( record . timestamp ) . format ( 'YYYY-MM-DDTHH:mm:ss.SSSZ' ) , message : record . message , error : JsonLayout . errorToSerializableObject ( record . error ) , log : { level : record . level . id . toUpperCase ( ) , logger : record . context , } , process : { pid : record . pid , } , } , record . meta ) ) ; } }