New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aws-lambda-powertools/logger

Package Overview
Dependencies
Maintainers
4
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-lambda-powertools/logger

The logging package for the AWS Lambda Powertools for TypeScript library

1.0.2
Source
npm
Version published
Weekly downloads
421K
5.64%
Maintainers
4
Weekly downloads
 
Created

What is @aws-lambda-powertools/logger?

@aws-lambda-powertools/logger is a structured logging utility designed for AWS Lambda functions. It simplifies the process of creating consistent and meaningful logs, which can be crucial for debugging and monitoring serverless applications.

What are @aws-lambda-powertools/logger's main functionalities?

Basic Logging

This feature allows you to log basic information. The logger.info method is used to log informational messages.

const { Logger } = require('@aws-lambda-powertools/logger');
const logger = new Logger();

exports.handler = async (event) => {
  logger.info('This is an info log');
  return { statusCode: 200, body: 'Hello World' };
};

Structured Logging

Structured logging allows you to add context to your logs, making them more useful for debugging and monitoring. You can add persistent attributes that will be included in every log entry.

const { Logger } = require('@aws-lambda-powertools/logger');
const logger = new Logger({
  persistentLogAttributes: {
    service: 'my-service',
    environment: 'production'
  }
});

exports.handler = async (event) => {
  logger.info('This is a structured log', { userId: '12345' });
  return { statusCode: 200, body: 'Hello World' };
};

Error Logging

This feature allows you to log errors with additional context. The logger.error method is used to log error messages.

const { Logger } = require('@aws-lambda-powertools/logger');
const logger = new Logger();

exports.handler = async (event) => {
  try {
    throw new Error('Something went wrong');
  } catch (error) {
    logger.error('An error occurred', { error });
  }
  return { statusCode: 500, body: 'Internal Server Error' };
};

Other packages similar to @aws-lambda-powertools/logger

Keywords

aws

FAQs

Package last updated on 19 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts