1.0.3 • Published 1 year ago

@atlantjs.dev/logger-winston-transporter v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Logger winston transporter

Logger transporter configuration using winston.

This logger has support to deliver logs without blocking the event loop to the console and/or elasticsearch.

Note: this library is intended to be used on Node applications where the process lifecycle can be controlled. DON'T USE THIS ON AWS LAMBDA!

Install

npm install @atlantjs.dev/logger-winston-transporter

Usage

Initialize the logger with logger-winston-transporter:

import { Logger } from "@atlantjs.dev/logger";
import { WinstonTransporter } from "@atlantjs.dev/logger-winston-transporter";

Logger.useTransporter(new WinstonTransporter("console:info:pretty"));

const logger = Logger.getLogger();
logger.info("Hello", { world: "!" });

Configuration

spec

Configures the log destination, level and format (when supported), on the format: {destination}:{level}:{~format}.

  • Possible values for destination: console or elasticsearch
  • Possible values for level: info or error
  • Possible values for format: pretty or json

Examples:

// send info and error logs to console, with a readable format
Logger.useTransporter(new WinstonTransporter("console:info:pretty"));

// send only error logs to console, with json format
Logger.useTransporter(new WinstonTransporter("console:error:json"));

// send logs to "elasticsearch", note: this destination can't be configured with a format
Logger.useTransporter(new WinstonTransporter("elasticsearch:info"));

// multiple destinations
Logger.useTransporter(
  new WinstonTransporter("console:error:pretty,elasticsearch:info")
);

options.elasticsearch.url

Optional, defaults to http://localhost:9200.

Elasticsearch endpoint url.

Note: this module is prepared to connect on AWS's Elasticsearch Service domains using AWS's environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION.

Example:

Logger.useTransporter(new WinstonTransporter("elasticsearch:info"), {
  elasticsearch: {
    endpoint: "https://myelasticsearchcluster.com",
  },
});

options.elasticsearch.indexPrefix

Optional, defaults to "logger".

Example:

// indices will be created as "my-logs-2021-04-01"
Logger.useTransporter(new WinstonTransporter("elasticsearch:info"), {
  elasticsearch: {
    indexPrefix: "my-logs",
  },
});

options.elasticsearch.flushInterval

Optional. defaults to 3000

Interval, in ms, where logs will be flushed to elasticsearch.

Example:

Logger.useTransporter(new WinstonTransporter("elasticsearch:info"), {
  elasticsearch: {
    flushInterval: 10000,
  },
});