pn-lambda-logger
Advanced tools
Comparing version
@@ -1,4 +0,6 @@ | ||
import { LogInput } from './LogInput'; | ||
import { LogLevels } from './logLevels'; | ||
import { LogOutput } from './LogOutput'; | ||
import { LogInput } from './types/LogInput'; | ||
import { LogInputError } from './types/LogInputError'; | ||
import { LogLevels } from './types/logLevels'; | ||
import { LogOptions } from './types/LogOptions'; | ||
import { LogOutput } from './types/LogOutput'; | ||
/** | ||
@@ -19,2 +21,37 @@ * Provides methods for writing logs to in different log-levels. Logs are written in JSON format to stdout using console.log(). | ||
/** | ||
* The id that came from the service that called this lambda. | ||
* It is best practice to send this through a header called X-REQUEST-ID. | ||
* In most cases you would set this to that header if it exist. | ||
*/ | ||
xRequestId: string | undefined; | ||
/** | ||
* The user agent that called this service. | ||
* In API Gateway events it can be found here: event.headers["User-Agent"] | ||
*/ | ||
useragent?: string; | ||
/** | ||
* The http verb (GET|POST...) | ||
* * In API Gateway events it can be found here: event.httpMethod | ||
*/ | ||
verb?: string; | ||
/** | ||
* The host of this service. | ||
* * In API Gateway events it can be found here: event.headers["Host"] | ||
*/ | ||
host?: string; | ||
/** | ||
* The host of this service. | ||
* * In API Gateway events it can be found here: event.queryStringParameters | ||
*/ | ||
query?: any; | ||
/** | ||
* The http path of this service. | ||
* * In API Gateway events it can be found here: event.path | ||
*/ | ||
path?: string; | ||
/** | ||
* Setup the meta data that will be added to all logs, this gives richer logs that will provide more value when they are sent to a log aggregator. | ||
*/ | ||
setup(options: LogOptions): void; | ||
/** | ||
* Prints an enriched log as JSON to stdout with newline. | ||
@@ -43,3 +80,3 @@ * @param logInput {message: 'This is my message', context: AwsLambdaContext, xRequestId: 'id-from-external-system', something: 'my property', somethingElse: 'another extra property' } | ||
*/ | ||
error(logInput: LogInput): void; | ||
error(logInput: LogInputError): void; | ||
private createLogJson; | ||
@@ -46,0 +83,0 @@ /** |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const logLevels_1 = require("./logLevels"); | ||
const logLevels_1 = require("./types/logLevels"); | ||
exports.LogLevels = logLevels_1.LogLevels; | ||
@@ -18,2 +18,15 @@ /** | ||
/** | ||
* Setup the meta data that will be added to all logs, this gives richer logs that will provide more value when they are sent to a log aggregator. | ||
*/ | ||
setup(options) { | ||
this.level = options.level || this.level; | ||
this.context = options.context || this.context; | ||
this.xRequestId = options.xRequestId || this.xRequestId; | ||
this.host = options.host || this.host; | ||
this.path = options.path || this.path; | ||
this.verb = options.verb || this.verb; | ||
this.query = options.query || this.query; | ||
this.useragent = options.useragent || this.useragent; | ||
} | ||
/** | ||
* Prints an enriched log as JSON to stdout with newline. | ||
@@ -75,2 +88,8 @@ * @param logInput {message: 'This is my message', context: AwsLambdaContext, xRequestId: 'id-from-external-system', something: 'my property', somethingElse: 'another extra property' } | ||
logOutput.message = logInput.message; | ||
logOutput.xRequestId = this.xRequestId; | ||
logOutput.host = this.host; | ||
logOutput.verb = this.verb; | ||
logOutput.path = this.path; | ||
logOutput.useragent = this.useragent; | ||
logOutput.query = this.query; | ||
/** | ||
@@ -83,3 +102,2 @@ * By using the lambda context we can easily add more rich logging. | ||
logOutput.functionName = context.functionName ? context.functionName : undefined; | ||
logOutput.functionVersion = context.functionVersion ? context.functionVersion : undefined; | ||
logOutput.invokedFunctionArn = context.invokedFunctionArn ? context.invokedFunctionArn : undefined; | ||
@@ -86,0 +104,0 @@ logOutput.logGroupName = context.logGroupName ? context.logGroupName : undefined; |
{ | ||
"name": "pn-lambda-logger", | ||
"version": "0.8.16", | ||
"version": "0.9.0", | ||
"description": "Logger for AWS Lambda nodejs.", | ||
@@ -46,3 +46,4 @@ "main": "dist/index.js", | ||
"exclude": [ | ||
"**/*.d.ts" | ||
"**/*.d.ts", | ||
"src/types/**/*" | ||
], | ||
@@ -49,0 +50,0 @@ "reporter": [ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
25242
27.59%23
35.29%401
45.82%1
Infinity%