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

@nekonomokochan/aws-lambda-node-logger

v1.1.2

Published

Logging library for AWS Lambda

Downloads

12

Readme

aws-lambda-node-logger

npm version Build Status Coverage Status License: MIT

Logging library for AWS Lambda

Getting Started

Install npm package

yarn

yarn add @nekonomokochan/aws-lambda-node-logger

npm

npm install --save @nekonomokochan/aws-lambda-node-logger

How To Use

Use With TypeScript

import * as lambda from "aws-lambda";
import { LambdaLoggerFactory, LogLevel } from "@nekonomokochan/aws-lambda-node-logger";

export const tsTest = async (event: lambda.APIGatewayEvent, context: lambda.Context, callback: lambda.Callback) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify({
      message: "TypeScript Test",
      input: event,
    }),
  };

  const error = new Error("TypeScript Error Test");

  const lambdaLogger = LambdaLoggerFactory.create(
    LogLevel.DEBUG,
    extractSlackTokenFromEnv(),
    extractSlackChannelFromEnv()
  );

  await lambdaLogger.error(error, true);
  await lambdaLogger.debug(context, true);

  callback(undefined, response);
};

/**
 * @return {string}
 */
const extractSlackTokenFromEnv = (): string => {
  const slackToken = process.env.AWS_LAMBDA_NODE_LOGGER_SLACK_TOKEN;
  if (typeof slackToken === "string") {
    return slackToken;
  }

  return "";
};

/**
 * @return {string}
 */
const extractSlackChannelFromEnv = (): string => {
  const slackChannel = process.env.AWS_LAMBDA_NODE_LOGGER_SLACK_CHANNEL;
  if (typeof slackChannel === "string") {
    return slackChannel;
  }

  return "";
};

This code is output as follows.

START RequestId: 1e46b449-6571-11e8-8af3-e7d42a6dbde1 Version: $LATEST
2018-06-01 16:55:14.864 (+09:00)	1e46b449-6571-11e8-8af3-e7d42a6dbde1	ERROR
 Error: TypeScript Error Test
    at exports.tsTest (/var/task/src/handler.ts:16:17)
    at invoke (/var/runtime/node_modules/awslambda/index.js:286:20)
    at InvokeManager.start (/var/runtime/node_modules/awslambda/index.js:151:9)
2018-06-01 16:55:14.864 (+09:00)	1e46b449-6571-11e8-8af3-e7d42a6dbde1	DEBUG
 { callbackWaitsForEmptyEventLoop: [Getter/Setter],
  done: [Function: done],
  succeed: [Function: succeed],
  fail: [Function: fail],
  logGroupName: '/aws/lambda/aws-lambda-node-logger-test-dev-tsTest',
  logStreamName: '2018/06/01/[$LATEST]66e583f2888346038abb3c08df758232',
  functionName: 'aws-lambda-node-logger-test-dev-tsTest',
  memoryLimitInMB: '1024',
  functionVersion: '$LATEST',
  getRemainingTimeInMillis: [Function: getRemainingTimeInMillis],
  invokeid: '1e46b449-6571-11e8-8af3-e7d42a6dbde1',
  awsRequestId: '1e46b449-6571-11e8-8af3-e7d42a6dbde1',
  invokedFunctionArn: 'arn:aws:lambda:ap-northeast-1:999999999999:function:aws-lambda-node-logger-test-dev-tsTest' }
END RequestId: 1e46b449-6571-11e8-8af3-e7d42a6dbde1
REPORT RequestId: 1e46b449-6571-11e8-8af3-e7d42a6dbde1	Duration: 0.94 ms	Billed Duration: 100 ms 	Memory Size: 1024 MB	Max Memory Used: 22 MB

Use With JavaScript

"use strict";

const awsLambdaNodeLogger = require("@nekonomokochan/aws-lambda-node-logger");

module.exports.jsTest = async (event, context, callback) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify({
      message: "JavaScript Test",
      input: event,
    }),
  };

  const error = new Error("JavaScript Error Test");

  const lambdaLogger = awsLambdaNodeLogger.LambdaLoggerFactory.create(
    awsLambdaNodeLogger.LogLevel.DEBUG,
    extractSlackTokenFromEnv(),
    extractSlackChannelFromEnv()
  );

  await lambdaLogger.debug(response, true);
  await lambdaLogger.error(error, true);

  callback(null, response);
};

/**
 * @return {string}
 */
const extractSlackTokenFromEnv = () => {
  const slackToken = process.env.AWS_LAMBDA_NODE_LOGGER_SLACK_TOKEN;
  if (typeof slackToken === "string") {
    return slackToken;
  }

  return "";
};

/**
 * @return {string}
 */
const extractSlackChannelFromEnv = () => {
  const slackChannel = process.env.AWS_LAMBDA_NODE_LOGGER_SLACK_CHANNEL;
  if (typeof slackChannel === "string") {
    return slackChannel;
  }

  return "";
};

output is the same as TypeScript.

License

MIT