import { schema } from '@kbn/config-schema' ; import { LogRecord , Layout } from '@kbn/logging' ; import { Conversion , LoggerConversion , LevelConversion , MetaConversion , MessageConversion , PidConversion , DateConversion , } from './conversions' ; /**
 * Default pattern used by PatternLayout if it's not overridden in the configuration.
 */ const DEFAULT_PATTERN = `[%date][%level][%logger] %message` ; export const patternSchema = schema . string ( { validate : ( string ) => { DateConversion . validate ! ( string ) ; } , } ) ; const patternLayoutSchema = schema . object ( { highlight : schema . maybe ( schema . boolean ( ) ) , type : schema . literal ( 'pattern' ) , pattern : schema . maybe ( patternSchema ) , } ) ; const conversions = [ LoggerConversion , MessageConversion , LevelConversion , MetaConversion , PidConversion , DateConversion , ] ; internal export interface PatternLayoutConfigType { type : 'pattern' ; highlight ? : boolean ; pattern ? : string ; } internal export class PatternLayout implements Layout { public static configSchema = patternLayoutSchema ; constructor ( private readonly pattern = DEFAULT_PATTERN , private readonly highlight = false ) { } param record public format ( record ) { let recordString = this . pattern ; for ( const conversion of conversions ) { recordString = recordString . replace ( conversion . pattern , conversion . convert . bind ( null , record , this . highlight ) ) ; } return recordString ; } }