Skip to content

Show function name in each log message #56

Answered by KyleRoss
kaihendry asked this question in Q&A
Discussion options

You must be logged in to vote

You can add it as part of your global metadata. Here's an example:

const log = require('lambda-log');

exports.handler = async function(event, context) {
	log.options.meta = {
		functionName: context.functionName
	};

	log.info('Test log');
	// => { "level": "info", "msg": "Test log", "functionName": "my-lambda-function", "_tags": [] }
};

Setting it within the global metadata will add the function name to every log automatically!

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by KyleRoss
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants