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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@financial-times/lambda-logger

v4.0.3

Published

Logger used by the lambda team. Logs in JSON format using pino

Downloads

893

Readme

lambda-logger

Logger useful for AWS lambda applications, particularly those which are aggregated in Splunk. Logs in JSON format using pino.

This was created to provide a simple logger, compatible with lambda, which outputs in a JSON format (n-logger) was previously used but didn't handle nested JSON fields or provide a JSON option).

This does make process.stdout.write a blocking function (process.stdout._handle.setBlocking(true);), as AWS Lambda previously streamed to an output which was synchronous, but has since changed to asynchronous behaviour, leading to lost logs.

CircleCI

Usage

const logger = require('@financial-times/lambda-logger');

logger.info({ importantField: 'some-field' }, 'Logging a thing');

Build exports

This module exports both

  • a commonjs build (the main field in package.json)
  • an ESM (ecmascript module) build (the module field in package.json)

If you're using commonjs and webpack, say with serverless-webpack it will try to load the ESM build out of the box. This exports a default export, and as such won't work if using commonjs.

The solutions to this problem are:

  1. Use import/export syntax locally and ensure your local tooling uses the ESM build, e.g. by using the esm module.
  2. Setup a webpack alias to the commonjs build:
// webpack.config.js

module.exports = {
    ...
	resolve: {
		alias: {
			// use commonjs export of lambda-logger to avoid having to use import/export syntax locally
			'@financial-times/lambda-logger':
				'@financial-times/lambda-logger/dist/lambda-logger.js',
		},
	},
};

API

The logger's API is identical to that of pino with the following exceptions:

  • The property sourcetype: _json is added to logs in production for Splunk compatibility.
  • Lambda related environment variables are added by default:
    • AWS_REGION
    • AWS_EXECUTION_ENV,
    • AWS_LAMBDA_FUNCTION_NAME,
    • AWS_LAMBDA_FUNCTION_MEMORY_SIZE,
    • AWS_LAMBDA_FUNCTION_VERSION
  • Defaults to ISO timestamp logging for splunk compatiblity. At the time of writing this incurs a 25% pino performance penalty.

Pino properties

Pino adds the following properties to logs by default:

  • level - the log level in string form. This is translated from the pino default of logging an integer representation.
  • v - the pino logger API version.
  • hostname - the hostname the process is running on.
  • pid - the process PID.

Configuration

  • NODE_ENV - pretty printing is enabled when value of NODE_ENV is not same as p, prod or production.
  • CONSOLE_LOG_LEVEL - determines the level to log at (pinto level option). Defaults to info.
  • SYSTEM_CODE - adds the systemCode property to every log.
  • ENVIRONMENT|STAGE - adds the environment property to every log. STAGE is used as a fallback due to it's default definition in the serverless framework.