lambda-monitor-logger
Advanced tools
Comparing version 3.3.0 to 4.0.0
@@ -1,20 +0,13 @@ | ||
"use strict"; | ||
import logger_ from './logic/logger.js'; | ||
import abbrev_ from './logic/abbrev.js'; | ||
import email_ from './logic/email.js'; | ||
import json_ from './logic/json.js'; | ||
import datadog_ from './logic/datadog.js'; | ||
import s3_ from './logic/s3.js'; | ||
const logger = require('./logic/logger'); | ||
const abbrev = require('./logic/abbrev'); | ||
const email = require('./logic/email'); | ||
const json = require('./logic/json'); | ||
const datadog = require('./logic/datadog'); | ||
const s3 = require('./logic/s3'); | ||
module.exports.logger = logger; | ||
module.exports.abbrev = abbrev; | ||
module.exports.email = email; | ||
module.exports.json = json; | ||
module.exports.datadog = datadog; | ||
module.exports.s3 = s3; | ||
export const logger = logger_; | ||
export const abbrev = abbrev_; | ||
export const email = email_; | ||
export const json = json_; | ||
export const datadog = datadog_; | ||
export const s3 = s3_; |
@@ -1,5 +0,3 @@ | ||
"use strict"; | ||
import util from 'util'; | ||
const util = require('util'); | ||
const callback = (match, idx, str) => { | ||
@@ -10,5 +8,6 @@ const prevChar = str[idx - 1]; | ||
module.exports = (value, { | ||
export default (value, { | ||
stripLineBreaks = true, | ||
maxLength = 512 | ||
maxLength = 512, | ||
replace = [] | ||
} = {}) => { | ||
@@ -23,7 +22,15 @@ const r = util.inspect(value, { | ||
} | ||
return str; | ||
} | ||
}); | ||
return stripLineBreaks ? r.replace(/\s*\n\s*/g, callback) : r; | ||
}; | ||
return replace | ||
.map(([k, v]) => [ | ||
typeof k === 'string' | ||
? new RegExp(k.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g') | ||
: k, | ||
v | ||
]) | ||
.filter(([k, v]) => k instanceof RegExp && ['string', 'function'].includes(typeof v)) | ||
.concat(stripLineBreaks ? [[/\s*\n\s*/g, callback]] : []) | ||
.reduce((p, [k, v]) => p.replace(k, v), r); | ||
}; |
@@ -1,6 +0,4 @@ | ||
"use strict"; | ||
import Joi from 'joi-strict'; | ||
const Joi = require('joi-strict'); | ||
const log = payload => { | ||
const log = (payload) => { | ||
// eslint-disable-next-line no-console | ||
@@ -10,14 +8,12 @@ console.log(`DATADOG: ${JSON.stringify(payload)}`); | ||
module.exports.logDistributionMetric = (metric, points, { | ||
tags = [] | ||
} = {}) => { | ||
Joi.assert(metric, Joi.string()); | ||
Joi.assert(points, Joi.alternatives(Joi.array().items(Joi.number().integer().min(0)), Joi.object().pattern(Joi.string().pattern(/^\d+$/), Joi.number().min(0)))); | ||
Joi.assert(tags, Joi.array().items(Joi.string())); | ||
log({ | ||
type: 'distribution-metric', | ||
args: [metric, points, { | ||
tags | ||
}] | ||
}); | ||
}; | ||
export default { | ||
logDistributionMetric: (metric, points, { tags = [] } = {}) => { | ||
Joi.assert(metric, Joi.string()); | ||
Joi.assert(points, Joi.alternatives( | ||
Joi.array().items(Joi.number().integer().min(0)), | ||
Joi.object().pattern(Joi.string().pattern(/^\d+$/), Joi.number().min(0)) | ||
)); | ||
Joi.assert(tags, Joi.array().items(Joi.string())); | ||
log({ type: 'distribution-metric', args: [metric, points, { tags }] }); | ||
} | ||
}; |
@@ -1,8 +0,7 @@ | ||
"use strict"; | ||
import Joi from 'joi-strict'; | ||
const Joi = require('joi-strict'); | ||
const emailFormat = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/; | ||
const emailFormat = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/; | ||
module.exports = { | ||
notify: obj => { | ||
export default { | ||
notify: (obj) => { | ||
Joi.assert(obj, Joi.object().keys({ | ||
@@ -13,4 +12,4 @@ from: Joi.string().pattern(emailFormat), | ||
body: Joi.string() | ||
})); // eslint-disable-next-line no-console | ||
})); | ||
// eslint-disable-next-line no-console | ||
console.log(`EMAIL: ${JSON.stringify({ | ||
@@ -23,2 +22,2 @@ from: obj.from, | ||
} | ||
}; | ||
}; |
@@ -1,11 +0,9 @@ | ||
"use strict"; | ||
import Joi from 'joi-strict'; | ||
const Joi = require('joi-strict'); | ||
module.exports = { | ||
log: obj => { | ||
Joi.assert(obj, Joi.object()); // eslint-disable-next-line no-console | ||
export default { | ||
log: (obj) => { | ||
Joi.assert(obj, Joi.object()); | ||
// eslint-disable-next-line no-console | ||
console.log(`JSON: ${JSON.stringify(obj)}`); | ||
} | ||
}; | ||
}; |
@@ -1,5 +0,3 @@ | ||
"use strict"; | ||
import abbrev from './abbrev.js'; | ||
const abbrev = require('./abbrev'); | ||
const logging = (type, msg) => { | ||
@@ -17,9 +15,17 @@ // eslint-disable-next-line no-console | ||
}; | ||
const levels = Object.keys(levelMap); | ||
module.exports = Object.entries(levelMap).reduce((prev, [level, names], idx) => Object.assign(prev, names.reduce((p, name) => Object.assign(p, { | ||
[name]: (...msgs) => { | ||
if (levels.indexOf((process.env.LOG_LEVEL || 'debug').toLowerCase()) <= idx) { | ||
msgs.forEach(msg => logging(level, msg)); | ||
} | ||
} | ||
}), {})), {}); | ||
export default Object.entries(levelMap).reduce( | ||
(prev, [level, names], idx) => Object.assign(prev, names.reduce( | ||
(p, name) => Object.assign(p, { | ||
[name]: (...msgs) => { | ||
if (levels.indexOf((process.env.LOG_LEVEL || 'debug').toLowerCase()) <= idx) { | ||
msgs.forEach((msg) => logging(level, msg)); | ||
} | ||
} | ||
}), | ||
{} | ||
)), | ||
{} | ||
); |
@@ -1,17 +0,14 @@ | ||
"use strict"; | ||
import Joi from 'joi-strict'; | ||
const Joi = require('joi-strict'); | ||
const log = (key, data) => { | ||
// eslint-disable-next-line no-console | ||
console.log(`S3: ${JSON.stringify({ | ||
key, | ||
data | ||
})}`); | ||
console.log(`S3: ${JSON.stringify({ key, data })}`); | ||
}; | ||
module.exports.logToS3 = (key, data) => { | ||
Joi.assert(key, Joi.string()); | ||
Joi.assert(data, Joi.object()); | ||
log(key, data); | ||
}; | ||
export default { | ||
logToS3: (key, data) => { | ||
Joi.assert(key, Joi.string()); | ||
Joi.assert(data, Joi.object()); | ||
log(key, data); | ||
} | ||
}; |
{ | ||
"name": "lambda-monitor-logger", | ||
"version": "3.3.0", | ||
"type": "module", | ||
"version": "4.0.0", | ||
"description": "Logging designed to be used with lambda-monitor", | ||
@@ -8,9 +9,9 @@ "main": "lib/index.js", | ||
"clean": "rm -rf lib", | ||
"build": "npx babel src --out-dir lib --copy-files --include-dotfiles --config-file ./.babelrc", | ||
"build": "cp -rf ./src ./lib", | ||
"build-clean": "yarn run clean && yarn run build", | ||
"test-simple": "nyc mocha \"./test/**/*.spec.js\"", | ||
"test-simple": "c8 mocha --experimental-loader=./test/hot.js \"./test/**/*.spec.js\"", | ||
"test": "yarn run clean && yarn run gardener && yarn run test-simple", | ||
"coveralls": "node ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info", | ||
"semantic-release": "yarn run build-clean && npx semantic-release", | ||
"gardener": "node gardener", | ||
"gardener": "node gardener.js", | ||
"docker": "docker run --net host -u`id -u`:`id -g` -v $(pwd):/user/project -v ~/.aws:/user/.aws -v ~/.npmrc:/user/.npmrc -w /user/project -it --entrypoint /bin/bash", | ||
@@ -43,3 +44,3 @@ "t": "yarn test", | ||
"dependencies": { | ||
"joi-strict": "2.0.0" | ||
"joi-strict": "2.0.1" | ||
}, | ||
@@ -53,58 +54,26 @@ "licenses": [ | ||
"devDependencies": { | ||
"@babel/cli": "7.14.8", | ||
"@babel/core": "7.15.0", | ||
"@babel/register": "7.15.3", | ||
"@blackflux/eslint-plugin-rules": "2.0.3", | ||
"@blackflux/robo-config-plugin": "5.3.0", | ||
"babel-eslint": "10.1.0", | ||
"babel-preset-latest-node": "5.5.1", | ||
"chai": "4.3.4", | ||
"@babel/core": "7.18.0", | ||
"@babel/eslint-parser": "7.17.0", | ||
"@babel/register": "7.17.7", | ||
"@blackflux/eslint-plugin-rules": "2.1.0", | ||
"@blackflux/robo-config-plugin": "7.8.2", | ||
"c8": "7.11.3", | ||
"chai": "4.3.6", | ||
"coveralls": "3.1.1", | ||
"eslint": "7.32.0", | ||
"eslint-config-airbnb-base": "14.2.1", | ||
"eslint-plugin-import": "2.24.2", | ||
"eslint": "8.15.0", | ||
"eslint-config-airbnb-base": "15.0.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"eslint-plugin-json": "3.1.0", | ||
"eslint-plugin-markdown": "2.2.0", | ||
"eslint-plugin-mocha": "9.0.0", | ||
"js-gardener": "3.0.3", | ||
"node-tdd": "3.0.4", | ||
"nyc": "15.1.0", | ||
"semantic-release": "17.4.7" | ||
"eslint-plugin-markdown": "2.2.1", | ||
"eslint-plugin-mocha": "10.0.3", | ||
"js-gardener": "3.0.5", | ||
"node-tdd": "3.4.1", | ||
"smart-fs": "3.0.1" | ||
}, | ||
"engines": { | ||
"node": ">= 12" | ||
"node": ">= 14" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"nyc": { | ||
"exclude": [ | ||
"gardener.js", | ||
"node_modules/*", | ||
"coverage/*", | ||
"lib/*" | ||
], | ||
"all": true, | ||
"babel": true, | ||
"branches": 100, | ||
"cache": true, | ||
"check-coverage": true, | ||
"extension": [], | ||
"functions": 100, | ||
"include": [ | ||
"**/*.js" | ||
], | ||
"lines": 100, | ||
"per-file": false, | ||
"report-dir": "./coverage", | ||
"reporter": [ | ||
"lcov", | ||
"text-summary" | ||
], | ||
"require": [ | ||
"@babel/register" | ||
], | ||
"statements": 100, | ||
"tempDir": "./coverage/.nyc_output" | ||
} | ||
] | ||
} |
@@ -24,3 +24,3 @@ # lambda-monitor-logger | ||
```js | ||
const { logger, abbrev } = require('lambda-monitor-logger'); | ||
import { logger, abbrev } from 'lambda-monitor-logger'; | ||
@@ -62,1 +62,10 @@ logger.error('Keyboard not found. Press F1 to Resume'); | ||
The maximum output length. | ||
### replace | ||
Type: `Array`<br> | ||
Default: `[]` | ||
Input needs to be of format `[[<STRING|REGEX>, <STRING|FUNCTION>], ...]` | ||
Allow custom replacement rules |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17
125
70
Yes
9518
+ Addedjoi@17.4.2(transitive)
+ Addedjoi-strict@2.0.1(transitive)
- Removedjoi@17.4.0(transitive)
- Removedjoi-strict@2.0.0(transitive)
Updatedjoi-strict@2.0.1