1.0.0-beta.4 • Published 1 year ago

winston-format-ec2 v1.0.0-beta.4

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

winston-format-ec2

A Winston (>= 3.x) format for prepending the AWS EC2 instance ID (e.g. i-abc123def456) onto your log statements.

The instance ID is loaded dynamically via the aws-sdk utilizing the MetadataService.

Installation

Installing

$ npm i winston-format-ec2

Usage

import winston from "winston"
import { ec2WinstonFormat } from "winston-format-ec2"

const logger = winston.createLogger({
  format: winston.format.combine(
    winston.format.simple(),
    ec2WinstonFormat(),
  ),
  level: "silly",
  transports: [
    new winston.transports.Console(),
  ],
})

logger.silly("You silly log statement") // Outputs 'i-abc123def456 silly: You silly log statement'

Format Options

ec2WinstonFormat({
  color: "\u001b", // If you want the instance ID to be colored
  maxLength: 7, // To take only the first few characters of the instance ID instead of the whole thing
})

Injecting MetadataService

You can also inject an instance of the AWS MetadataService:

import AWS from "aws-sdk"
import { ec2WinstonFormat } from "winston-format-ec2"

const metadataService = new AWS.MetadataService()
const format = ec2WinstonFormat({
  awsMetadataService: metadataService,
})

Author: Mike Richards

1.0.0-beta.4

1 year ago

1.0.0-beta.3

1 year ago

1.0.0-beta.2

1 year ago

1.0.0-beta.1

1 year ago

1.0.0-beta.0

1 year ago

1.0.0-dev.0

1 year ago