# BaseAppender Class

Module
import { BaseAppender } from "@tsed/logger"
Source/packages/logger/src/appenders/class/BaseAppender.ts

# Overview

abstract class BaseAppender implements IBaseAppender {
<span class="token punctuation">[</span>key<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">]</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
<span class="token keyword">constructor</span><span class="token punctuation">(</span>_config<span class="token punctuation">:</span> <a href="/api/logger/appenders/interfaces/IAppenderConfiguration.html"><span class="token">IAppenderConfiguration</span></a><span class="token punctuation">)</span><span class="token punctuation">;</span>
get <span class="token function">config</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/logger/appenders/interfaces/IAppenderConfiguration.html"><span class="token">IAppenderConfiguration</span></a><span class="token punctuation">;</span>
<span class="token function">configure</span><span class="token punctuation">(</span>config<span class="token punctuation">:</span> <a href="/api/logger/appenders/interfaces/PartialAppenderConfiguration.html"><span class="token">PartialAppenderConfiguration</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> this<span class="token punctuation">;</span>
/**
 *
 * @param args
 */
<span class="token function">layout</span><span class="token punctuation">(</span>...args<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
<span class="token keyword">abstract</span> <span class="token function">write</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><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>

}

# Description

# BaseAppender

ts-log-debug 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:

// consoleAppender.ts
import {Appender, BaseAppender, LogEvent} from "ts-log-debug";
const consoleLog = console.log.bind(console);

@ Appender({name: "console2"})
export class ConsoleAppender extends BaseAppender {
  write(loggingEvent: LogEvent) {
      consoleLog(this.layout(loggingEvent, this.config.timezoneOffset));
  }
}
1
2
3
4
5
6
7
8
9
10

This appender can be use like this:

import {Logger} from "ts-log-debug";
import "./consoleAppender.ts"

const logger = new Logger("loggerName");

logger.appenders
  .set("console-log", {
      type: "console2", level: ["debug", "info", "trace"]
  });
1
2
3
4
5
6
7
8
9

# Members

[key: string]: any;

get config(): IAppenderConfiguration;

configure(config: PartialAppenderConfiguration): this;

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

abstract write(loggingEvent: LogEvent): any;

Other topics