Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Try using awslambda.sendConsoleLogs internal call if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie Briggs committed Jul 27, 2018
1 parent c87995b commit 101c5b4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
extends: ['@financial-times/de-tooling', 'prettier'],
plugins: ['prettier'],
globals: { awslambda: true },
rules: {
'prettier/prettier': 'error',
},
Expand Down
14 changes: 12 additions & 2 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//
const pino = require('pino');

const isProduction = () => process.env.NODE_ENV === 'production';
Expand All @@ -14,12 +15,21 @@ const stringifyVersion = chunk =>
`${keyString}"${pino.levels.labels[parseInt(levelString, 10)]}"`
);

const writeLambdaLog = chunk => {
return awslambda.sendConsoleLogs(stringifyVersion(chunk));
};

const writeLog = chunk => {
process.stdout.write(stringifyVersion(chunk));
return process.stdout.write(stringifyVersion(chunk));
};

const getProductionStream = () => ({
write: writeLog,
write:
isLambda() &&
awslambda &&
typeof awslambda.sendConsoleLogs === 'function'
? writeLambdaLog
: writeLog,
});

const getPrettyPrintedStream = () => {
Expand Down

0 comments on commit 101c5b4

Please sign in to comment.