New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

metric-logger

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metric-logger - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

.nvmrc

62

index.js
module.exports = {
logMetric: logMetric,
// logMetric2: logMetric2,
logMetric: logMetric
};
function logMetric(metric) {
let o = Object.assign({
node_env: process.env.NODE_ENV
function logMetric(metric, opts) {
let obj = Object.assign({
node_env: process.env.NODE_ENV,
// pid: process.pid
}, metric);
let log = 'METRIC ' + toKeyValue(obj, opts);
console.log(log);
return log;
}
var log = "METRIC " + Object.keys(o).map((key) => {
let val = o[key];
var string = JSON.stringify(val)
if (string && string.indexOf('{') == 0) {
string = string.replace(/"/g,'\\"');
string = '"'+string+'"';
function toKeyValue(obj, opts = {}, prefix) {
return Object.keys(obj).map(k => {
const v = obj[k];
const prefixedKey = typeof prefix !== typeof undefined ? prefix + "__" + k : k; //add prefix if provided
if (opts.deepPrefix && typeof v === typeof {} && !Array.isArray(v)) {
return toKeyValue(v, opts, prefixedKey);
}
return `${prefixedKey}=${escape(v)}`
}).join(' ')
}
return key + '=' + string
const escape = v => {
let string = JSON.stringify(v);
return string.startsWith('{') || string.startsWith('[') ? JSON.stringify(string) : string
}
}).join(" ");
console.log(log);
return log;
}
//
// function logMetric2(metric) {
// let o = Object.assign({
// node_env: process.env.NODE_ENV
// }, metric);
//
//
// var log = "METRIC " + Object.keys(o).map((key) => {
// let val = o[key];
// var string = JSON.stringify(val)
// if (string && string.indexOf('{') == 0) {
// string = string.replace(/"/g, '\\"');
// string = '"' + string + '"';
// }
//
// return key + '=' + string
//
// }).join(" ");
// console.log(log);
// return log;
// }
//
{
"name": "metric-logger",
"version": "1.0.2",
"version": "1.0.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -17,8 +17,10 @@ var logMetric = require('../index.js').logMetric;

it('should serialise json properly', function() {
var json = { w: 1, x: "blah", w: [0,1,"2"], z: { a: "1", 1: 2 }};
var json = { w: 1, x: "blah", w: [0,1,"spaced words"], z: { a: "1", 1: 2, "withquotes": '"test"(*&^%$£!' }};
assert.equal(logMetric({ json: json }), expected('json='+JSON.stringify('{\"w\":[0,1,\"spaced words\"],\"x\":\"blah\",\"z\":{\"1\":2,\"a\":\"1\",\"withquotes\":\"\\"test\\"(*&^%$£!\"}}') ));
});
assert.equal(logMetric({ json: json }), expected('json="{\\"w\\":[0,1,\\"2\\"],\\"x\\":\\"blah\\",\\"z\\":{\\"1\\":2,\\"a\\":\\"1\\"}}"' ));
it('should prefix deep structures', function() {
var json = { w: 1, x: "blah", deep: {"z": 5}, array: [1,2,"spaced words"]};
assert.equal(logMetric({ json: json }, { deepPrefix: true}), expected('json__w=1 json__x="blah" json__deep__z=5 json__array="[1,2,\\"spaced words\\"]"' ));
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc