PatternLayout
@tsed/logger
Usage
typescript
import { PatternLayout } from "@tsed/logger";
See /packages/logger/src/types/common/layouts/components/PatternLayout.ts.
Overview
ts
class PatternLayout extends BaseLayout {
static LayoutReplacer: any;
constructor(config: BasicLayoutConfiguration);
transform(loggingEvent: LogEvent, timezoneOffset?: number): string;
}
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
- %j log data as JSON
- %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.
static LayoutReplacer
ts
static LayoutReplacer: any;
transform
ts
transform(loggingEvent: LogEvent, timezoneOffset?: number): string;