# PatternLayout Class return authors

import { PatternLayout } from "@tsed/logger"

# Overview

class PatternLayout extends BaseLayout {
<span class="token keyword">constructor</span><span class="token punctuation">(</span>config<span class="token punctuation">:</span> <a href="/api/logger/layouts/interfaces/IBasicLayoutConfiguration.html"><span class="token">IBasicLayoutConfiguration</span></a><span class="token punctuation">)</span><span class="token punctuation">;</span>
 * @param loggingEvent
 * @param timezoneOffset
 * @returns <span class="token punctuation">{</span><span class="token keyword">string</span><span class="token punctuation">}</span>
<span class="token function">transform</span><span class="token punctuation">(</span>loggingEvent<span class="token punctuation">:</span> <a href="/api/logger/core/LogEvent.html"><span class="token">LogEvent</span></a><span class="token punctuation">,</span> timezoneOffset?<span class="token punctuation">:</span> <span class="token keyword">number</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>


# Description

PatternLayout Format for specifiers is %[padding].[truncation][field]{[format]} e.g. %5.10p - left pad the log level by 5 characters, up to a max of 10 Fields can be any of:

  • %r time in toLocaleTimeString format
  • %p log level
  • %c log category
  • %h hostname
  • %m log data
  • %d date in constious formats
  • %% %
  • %n newline
  • %z pid
  • %x{[tokenname]} add dynamic tokens to your log. Tokens are specified in the tokens parameter You can use %[ and %] to define a colored block.

Tokens are specified as simple key:value objects. The key represents the token name whereas the value can be a string or function which is called to extract the value to put in the log message. If token is not found, it doesn't replace the field.

A sample token would be: { 'pid' : function() { return process.pid; } }

Takes a pattern string, array of tokens and returns a layouts function.

# Members

transform(loggingEvent: LogEvent, timezoneOffset?: number): string;

Other topics