From 196d518641599737c0f9360fc1167ec1cea80f64 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Wed, 9 Aug 2017 10:43:32 +0200 Subject: [PATCH] Dedicated handling for AWS Lambda environment --- src/node.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/node.js b/src/node.js index b85ec7e3..0a3547bb 100644 --- a/src/node.js +++ b/src/node.js @@ -66,6 +66,8 @@ exports.inspectOpts = Object.keys(process.env).filter(function (key) { return obj; }, {}); +var isAWSLambdaEnv = Boolean(process.env.AWS_LAMBDA_LOG_STREAM_NAME); + /** * Is stdout a TTY? Colored output is enabled when `true`. */ @@ -112,6 +114,8 @@ function formatArgs(args) { args[0] = prefix + args[0].split('\n').join('\n' + prefix); args.push(colorCode + 'm+' + exports.humanize(this.diff) + '\u001b[0m'); + } else if (isAWSLambdaEnv) { + args[0] = name + ' ' + args[0]; } else { args[0] = new Date().toISOString() + ' ' + name + ' ' + args[0]; @@ -123,6 +127,11 @@ function formatArgs(args) { */ function log() { + if (isAWSLambdaEnv) { + // AWS Lambda env decorates console.* methods with meaningful debug info + // therefore we rely on them directly + return console.error(util.format.apply(util, arguments)); + } return process.stderr.write(util.format.apply(util, arguments) + '\n'); }