
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
pn-lambda-logger
Advanced tools
import { APIGatewayEvent } from 'aws-lambda';
import { log } from 'pn-lambda-logger';
import { ok } from '../aws/response';
export const healthCheck = async (event: APIGatewayEvent, context: AWSLambda.Context, cb: AWSLambda.Callback) => {
// A standard INFO log message
log.info('My message');
}
// Output
{
"@timestamp": 1541421856289,
"level": "INFO",
"message": "My message"
}
import { APIGatewayEvent } from 'aws-lambda';
import { log } from 'pn-lambda-logger';
import { ok } from '../aws/response';
export const healthCheck = async (event: APIGatewayEvent, context: AWSLambda.Context, cb: AWSLambda.Callback) => {
// Setup so that the AWS Lambda meta data will be added to log output
log.setup({ context, host: event.headers['Host'], verb: event.httpMethod, useragent: event.headers['User-Agent'], query: event.queryStringParameters, path: event.path, xRequestId: event.headers['X-REQUEST-ID'] });
// A standard INFO log message
log.info({ message: 'Message' });
cb(null, ok({ status: 'UP' }));
};
{
"@timestamp": 1541460988579,
"level": "INFO",
"message": "Message",
"host": "abc123.execute-api.eu-west-1.amazonaws.com",
"verb": "GET",
"path": "/manage/health",
"useragent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
"query": {
"hello": "world"
},
"awsRequestId": "asdas-adsas-asdasdas-asdasda-adss",
"functionName": "hello",
"invokedFunctionArn": "arn:cccccc",
"memoryLimitInMB": 1024,
"remainingTime": 11147
}
The default log level is INFO log.level = LogLevels.INFO;
.
To show debug messages you need to explicitly set the log.level to DEBUG like this:
// Set loglevel
log.level = LogLevels.DEBUG;
// Write debug log
log.debug({ message: 'message' });
{
"@timestamp": 1541421856291,
"level": "DEBUG",
"message": "Message",
}
You can add any number of extra properties to the object when logging, like this:
// Setup so that the AWS Lambda meta data will be added to log output
log.setup({ context, host: event.headers['Host'], verb: event.httpMethod, useragent: event.headers['User-Agent'], query: event.queryStringParameters, path: event.path, xRequestId: event.headers['X-REQUEST-ID'] });
// Write info log
log.info({ message: 'Message', myProp: 'hello', myNestedProp: {subProp: 'something'} });
{
stdoutHijacker.ts:12
"@timestamp": 1541429192677,
"level": "INFO",
"message": "Message",
"host": "abc123.execute-api.eu-west-1.amazonaws.com",
"verb": "GET",
"path": "/manage/health",
"useragent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
"query": {
"hello": "world"
},
"awsRequestId": "a3de505e-f16b-42f4-b3e6-bcd2e4a73903",
"functionName": "ExampleCloudFormationStackName-ExampleLambdaFunctionResourceName-AULC3LB8Q02F",
"functionVersion": "$LATEST",
"invokedFunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:ExampleCloudFormationStackName-ExampleLambdaFunctionResourceName-AULC3LB8Q02F",
"memoryLimitInMB": 128,
"remainingTime": 3,
"myProp": "hello",
"myNestedProp": {
"subProp": "something"
}
}
log.level = LogLevels.OFF;
You can easily set the initial log level by setting the environment variable PN_LOG_LEVEL
. This can be useful for setting different log levels in different environments TEST|PROD etc. Use 'OFF', 'DEBUG', 'INFO', 'WARN' or 'ERROR', like this:
PN_LOG_LEVEL: 'DEBUG'
FAQs
Logger for AWS Lambda nodejs.
The npm package pn-lambda-logger receives a total of 3,318 weekly downloads. As such, pn-lambda-logger popularity was classified as popular.
We found that pn-lambda-logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 49 open source maintainers collaborating on the project.
Did you know?
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.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.