winston-format-ec2
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.4 • Public • Published

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

Package Sidebar

Install

npm i winston-format-ec2

Weekly Downloads

2

Version

1.0.0-beta.4

License

MIT

Unpacked Size

9.98 kB

Total Files

9

Last publish

Collaborators

  • drwhat