Constructs a new LayoutImpl with an optional custom formatter.
Optionalformatter: LayoutFormatter(Optional) A function that formats a LogEvent as a string.
If omitted, uses the default formatter: [timestamp] [type] message.
The formatter must accept a single LogEvent parameter, and return a string.
ScriptError if the formatter is invalid or the instance is misconfigured.ScriptError if:
null or undefined.null or undefined (e.g., due to subclassing or mutation).// Default formatter:
const layout = new LayoutImpl()
// Custom JSON formatter:
const jsonLayout = new LayoutImpl(event => JSON.stringify(event))
// XML formatter:
const xmlLayout = new LayoutImpl(event =>
  `<log><type>${event.type}</type><message>${event.message}</message></log>`
)
// Short format: [type] message
const shortLayout = new LayoutImpl(e => `[${LOG_EVENT[e.type]}] ${e.message}`)
// Named function for better diagnostics in toString():
const namedShortLayout = new LayoutImpl(
  function shortLayoutFun(e: LogEvent): string { return `[${LOG_EVENT[e.type]}] ${e.message}` }
)
StaticdefaultConvenience static property to define a long formatter used as default, e.g. [timestamp] [type] message.
This is the default formatter used if no custom formatter is provided.
StaticshortConvenience static property to define a short formatter, e.g. [type] message.
Formats the given log event as a string.
The log event to format.
A string representation of the log event.
A string representation of the layout. If the formatter is a function, it returns the name of the function.
StaticvalidateAsserts that the provided object implements the Layout interface.
Checks for the public format method (should be a function taking one argument).
It used by LayoutImpl and appenders to ensure that the layout is valid before using it.
The object to validate as a Layout implementation.
Optionalcontext: string(Optional) Additional context for error messages.
Default implementation of the
Layoutinterface. Formats log events into a string using a provided or default formatting function.Remarks
LogEventinterface before formatting.ScriptErrorif the event does not conform to the expectedLogEventinterface.See