UNPKG

lambee

Version:

A tool to help developer work with AWS Lambda.

35 lines (32 loc) 1.26 kB
const R = require('ramda') const eol = require('eol') const chalk = require('chalk') const justMessages = R.map(R.prop('message')) const fixEol = R.map(eol.auto) const splashOfColor = R.map(R.cond([ [R.test(/^END/), chalk.gray], [R.test(/^START/), chalk.gray], [R.test(/^REPORT/), chalk.gray], [R.test(/\sDEBUG\s/), chalk.gray], [R.test(/\sWARN\s/), chalk.yellow], [R.test(/\sERROR\s/), chalk.red], [R.T, chalk.white] ])) const filterFine = R.compose( R.filter(R.complement(R.startsWith('END'))), R.filter(R.complement(R.startsWith('START'))), R.filter(R.complement(R.startsWith('REPORT'))) ) const filterDebug = R.filter(R.complement(R.test(/DEBUG/))) const filterInfo = R.filter(R.complement(R.test(/INFO/))) /** * Pretty print only relevant lambda function logs. */ module.exports = (logLevel) => { switch (logLevel) { case 1: return R.pipe(justMessages, fixEol, splashOfColor, R.join('\n')) case 2: return R.pipe(justMessages, fixEol, filterFine, splashOfColor, R.join('\n')) case 3: return R.pipe(justMessages, fixEol, filterFine, filterDebug, splashOfColor, R.join('\n')) case 4: return R.pipe(justMessages, fixEol, filterFine, filterDebug, filterInfo, splashOfColor, R.join('\n')) } }