npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

log-winston-aws-level

v1.11.0

Published

A logger for aws lambda functions on the top of winston library supporting correlationId , log level at run time, json formatted messages, and execution time for lambda

Downloads

688

Readme

Supports CorrelationId, Dynamic log level at runtime, json formatted result

Not only you have access to all Winston library methods, but also you have some extra methods specific for AWS lambda function.

How to install

npm i log-winston-aws-level

How to use

in the AWS lambda handler import the logger as below:

const logger = require('log-winston-aws-level');

now you have access to all winston methods as well as a few more which are handy for aws lambda.

log handy details in the lambda function entry point

By calling entryPoint method, we can catch some initial details like:

   CorrelationId,  Http,  FunctionName ,Path, Request,  Headers 

What it returns is the CorrelationId as well as start time. We will use this value to calculate Duration Time when the function successfully finished.

   let loggParams = logger.entryPoint(event, context);
   const CorrelationId= loggParams.CorrelationId;

You need to pass this CorrelationId somehow to all the methods you need to relate it with your lambda function.

What should be logged when the function successfully finished

At this point we need to log CorrelationId, Duration time and the Response. We can call it as per below:

 logger.endPoint(result, logParams);

This will log more details like Body and Status code.

Format the log message

In this library, we only set up console as transport and format the logged message with the following format:

const formatter = options => {
    const timestamp = options.timestamp();
    let level = options.level.toUpperCase();

    const message = options.message || '';
    const metaPresent = options.meta && Object.keys(options.meta).length;
    const meta = metaPresent ? `\n\t${JSON.stringify(options.meta)}` : '';
    return `${timestamp} ${level} ${message} ${meta} `;
};

All the log methods by default will pass through this Format method. Even direct methods of Winston like logger.info(params) and so on.

How to format Error callback object

Basically when an error happens, the error object might have error message, stack error, status or CorrelationId. Having said that, it is good to have a transformer to format the error object as a json object.

try{
    method()
}
catch(err){
    let error = logger.errTransformer(err,CorrelationId);
}

This method also supports complex objects and resolves the issue of typeerror converting circular structure to json.

and then the object would be transformed to a json.

How to set the log level at runtime:

In fact the default log level is what we have in Winston library so Error, info,... are priority. Debug is basically one of the least priority which means when you use logger.debug it won’t log unless you change the priority.

  logger.updateLevel('debug');
  logger.debug('the message just for debugging');

Now it works and debug level will log the messages.

How to pass the log level at runtime dynamically:

There are some ways to pass the log level such as pass it in path parameter, body or header.

module.exports.lambdaMethod = (event, context, callback) => {
 if ((event.headers) && (event.headers['level'])) {
    process.env.LOGLEVEL = event.headers['level'];
    logger.updateLevel(process.env.LOGLEVEL);
  }
  else process.env.LOGLEVEL = 'info';

let’s say we want to log in debug level inside methods. So whenever you import the logger and really want to log in debug level you need to update the level. As an example is inside lambda Method we want to invoke another method called validate which is inthe identity class, so we need to pass CorrelationId then we can keep track of all invocation for a specific request in the cloud watch.

module.exports = class identity {
  constructor(Token, CorrelationId) {
    this.Token = Token;
    this.CorrelationId = CorrelationId
  }

  validate() {
    logger.updateLevel(process.env.LOGLEVEL);
    logger.debug(this.Token, this.CorrelationId);

so if you passed the log level at run time, in the entry point you would keep it in the process.env.LOGLEVEL. Consequently the next line which is logger.debug will be executed. Following this pattern, you can potentially log lots of details which are only useful when you want to debug your code but you don’t actually log these unnecessary detail in the normal situation.

Sample

Inside sample folder, you can see 2 files which are kind of aws lambda functions mock. You have a handler method which is really the first entry point of your function. You also have a trigger file (mocking API gateway) including mocked event and context and callback methods and makes a call to handler.