@everymundo/simple-logr
Advanced tools
Comparing version 3.1.2 to 3.2.0
88
index.js
@@ -6,3 +6,3 @@ 'use strict' | ||
const createDefaultOptions = (env) => ({ | ||
const createDefaultOptions = (env, options = {}) => ({ | ||
createdAt: Date.now(), | ||
@@ -27,64 +27,58 @@ level: env.LOG_LEVEL || 'info', | ||
}, | ||
get makeItShort () { | ||
return env.LOG_SHORT !== 'false' | ||
}, | ||
makeItShort: env.LOG_SHORT !== 'false', | ||
formatters: { | ||
level: label => ({ level: label }) | ||
}, | ||
base: null | ||
base: null, | ||
...options | ||
}) | ||
const defaultOptions = createDefaultOptions(process.env) | ||
const createLogger = (options) => { | ||
const pinoOptions = createDefaultOptions(process.env, options) | ||
// Default is this | ||
// ',"pid":2365,"hostname":"daniel-XPS-15-7590"' | ||
function setRequestId (RequestId, substrStart = -12, substrEnd) { | ||
this.requestId = this.madeShort | ||
? ('' + RequestId).slice(substrStart, substrEnd) | ||
: RequestId | ||
const logr = Object.create(pino(pinoOptions), { | ||
createLogger: { value: createLogger }, | ||
setRequestId: { | ||
value: function (RequestId, substrStart = -12, substrEnd) { | ||
this.requestId = this.madeShort | ||
? ('' + RequestId).slice(substrStart, substrEnd) | ||
: RequestId | ||
this[pino.symbols.chindingsSym] = flatstr(`,"Id":"${this.requestId}"`) | ||
} | ||
this[pino.symbols.chindingsSym] = flatstr(`,"Id":"${this.requestId}"`) | ||
} | ||
}, | ||
requestId: { value: null, writable: true }, | ||
makeItShort: { | ||
value: function () { | ||
this.madeShort = true | ||
function makeItShort () { | ||
this.madeShort = true | ||
for (const k of Object.keys(this[pino.symbols.lsCacheSym])) { | ||
if (process.env.LOG_NUMERIC_LEVEL === 'true') { | ||
this[pino.symbols.lsCacheSym][k] = flatstr(`{"l":${k}`) | ||
} else { | ||
const { level } = JSON.parse(`${this[pino.symbols.lsCacheSym][k]}}`) | ||
for (const k of Object.keys(this[pino.symbols.lsCacheSym])) { | ||
if (process.env.LOG_NUMERIC_LEVEL === 'true') { | ||
this[pino.symbols.lsCacheSym][k] = flatstr(`{"l":${k}`) | ||
} else { | ||
const { level } = JSON.parse(`${this[pino.symbols.lsCacheSym][k]}}`) | ||
this[pino.symbols.lsCacheSym][k] = (typeof level === 'number') | ||
? flatstr(`{"l":"${this.levels.labels[level][0]}"`) | ||
: flatstr(`{"l":"${level[0]}"`) | ||
} | ||
} | ||
} | ||
}, | ||
madeShort: { value: false, writable: true }, | ||
createdAt: { value: Date.now() }, | ||
createDefaultOptions: { value: createDefaultOptions } | ||
}) | ||
this[pino.symbols.lsCacheSym][k] = (typeof level === 'number') | ||
? flatstr(`{"l":"${this.levels.labels[level][0]}"`) | ||
: flatstr(`{"l":"${level[0]}"`) | ||
} | ||
} | ||
} | ||
const createLogger = (options = {}) => { | ||
const pinoOptions = { ...defaultOptions, ...options } | ||
const mainLogr = Object.create( | ||
pino(pinoOptions), | ||
{ | ||
createLogger: { value: createLogger }, | ||
setRequestId: { value: setRequestId }, | ||
requestId: { value: null, writable: true }, | ||
makeItShort: { value: makeItShort }, | ||
// madeShort: { value: false, writable: true }, | ||
createdAt: { value: pinoOptions.createdAt, writable: true }, | ||
createDefaultOptions: { value: createDefaultOptions } | ||
} | ||
) | ||
if (pinoOptions.makeItShort) { | ||
mainLogr.makeItShort() | ||
logr.makeItShort() | ||
} | ||
mainLogr[pino.symbols.endSym] = '}\n' | ||
Object.defineProperty(mainLogr, 'default', { value: mainLogr }) | ||
logr[pino.symbols.endSym] = '}\n' | ||
Object.defineProperty(logr, 'default', { value: logr }) | ||
return mainLogr | ||
return logr | ||
} | ||
// module.exports = SimpleLogr.createLogger() | ||
module.exports = createLogger() |
{ | ||
"name": "@everymundo/simple-logr", | ||
"version": "3.1.2", | ||
"version": "3.2.0", | ||
"description": "A very simplistic logger that allows one to avoid using the console.log directly allowing stubbing and better linting.", | ||
@@ -8,4 +8,4 @@ "main": "index.js", | ||
"scripts": { | ||
"cover": "LOG_LEVEL=silent nyc -x test --reporter=lcov --reporter=text mocha test --recursive", | ||
"check-coverage": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100", | ||
"cover": "LOG_LEVEL=silent c8 -x test --reporter=lcov --reporter=text mocha test --recursive", | ||
"check-coverage": "LOG_LEVEL=silent c8 check-coverage --statements 100 --branches 100 --functions 100 --lines 100", | ||
"check-lint": "standard *js *mjs *cjs test/*js", | ||
@@ -38,9 +38,8 @@ "fix-lint": "standard --fix *js *mjs *cjs test/*js", | ||
"@std/esm": "^0.26.0", | ||
"c8": "^7.13.0", | ||
"chai": "^4.3.7", | ||
"c8": "^8.0.1", | ||
"chai": "^4.3.10", | ||
"coverage-node": "^8.0.0", | ||
"esm": "^3.2.25", | ||
"mocha": "^10.2.0", | ||
"nyc": "^15.1.0", | ||
"sinon": "^15.0.4", | ||
"sinon": "^16.1.0", | ||
"standard": "^17.0.0" | ||
@@ -50,4 +49,4 @@ }, | ||
"flatstr": "^1.0.12", | ||
"pino": "^8" | ||
"pino": "^8.16.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
9
0
14008
8
204
Updatedpino@^8.16.0