UNPKG

simple-leveled-log-methods

Version:

a simple and opinionated logging library. plays well with aws lambda + cloudwatch.

39 lines 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatLogContentsForEnvironment = void 0; const constants_1 = require("./constants"); const identifyEnvironment_1 = require("./identifyEnvironment"); const formatLogContentsForEnvironment = ({ level, timestamp, message, metadata, }) => { const env = (0, identifyEnvironment_1.identifyEnvironment)(); // if its a "local" environment, then dont stringify the contents - but stringify the metadata to cut down on visual noise if (env === constants_1.SupportedEnvironment.LOCAL) { return { level, timestamp, message, metadata: JSON.stringify(metadata), // json stringify it to cut down on the visual noise in the console }; } // if its an aws-lambda environment, then stringify the contents - without stringifying the metadata - to make sure log is fully readable and parseable by cloudwatch if (env === constants_1.SupportedEnvironment.AWS_LAMBDA) { return JSON.stringify({ level, timestamp, message, metadata, }); } // if its a web-browser environment, then dont stringify the contents - nor the metadata - to make sure log is fully accessible through console devtools if (env === constants_1.SupportedEnvironment.WEB_BROWSER) { return { level, timestamp, message, metadata, }; } // if it was not one of the above, we have not supported this environment yet throw new Error('unsupported environment detected. this should never occur - and is a bug within simple-leveled-log-methods'); // fail fast }; exports.formatLogContentsForEnvironment = formatLogContentsForEnvironment; //# sourceMappingURL=formatLogContentsForEnvironment.js.map