Skip to content

BaseAppender

@tsed/logger

Usage

typescript
import { BaseAppender } from "@tsed/logger";

See /packages/logger/src/types/common/appenders/class/BaseAppender.ts.

Overview

ts
abstract class BaseAppender<Opts = any> implements BaseAppenderMethods {
    readonly config: AppenderConfiguration<Opts>;
    [key: string]: any;
    constructor(config: AppenderConfiguration<Opts>);
    get appenderOptions(): AppenderOptions;
    configure(config: PartialAppenderConfiguration): this;
    layout(...args: any[]): string;
    abstract write(loggingEvent: LogEvent): any;
}

Description

BaseAppender

@tsed/logger can load appenders from outside the core appenders. The type config value is used as a require path if no matching appender can be found. For example, the following configuration will create an appender with decorators:

typescript
// consoleAppender.ts
import {Appender, BaseAppender, LogEvent} from "@tsed/logger";
const consoleLog = console.log.bind(console);

@ Appender({name: "console2"})
export class ConsoleAppender extends BaseAppender {
  write(loggingEvent: LogEvent) {
      consoleLog(this.layout(loggingEvent, this.config.timezoneOffset));
  }
}

This appender can be use like this:

typescript
import {Logger} from "@tsed/logger";
import "./consoleAppender.ts"

const logger = new Logger("loggerName");

logger.appenders
  .set("console-log", {
      type: "console2", level: ["debug", "info", "trace"]
  });

readonly config

ts
readonly config: AppenderConfiguration<Opts>;

[key: string]

ts
[key: string]: any;

get appenderOptions

ts
get appenderOptions(): AppenderOptions;

configure

ts
configure(config: PartialAppenderConfiguration): this;

layout

ts
layout(...args: any[]): string;

abstract write

ts
abstract write(loggingEvent: LogEvent): any;

Released under the MIT License.