@everymundo/simple-logr
Advanced tools
Comparing version 1.1.0 to 1.1.1
57
index.js
@@ -16,3 +16,3 @@ 'use strict'; | ||
const should = {}; | ||
/* const should = {}; | ||
@@ -26,3 +26,3 @@ Object.defineProperties(should, { | ||
fatal: {value: true}, | ||
}); | ||
}); */ | ||
@@ -38,2 +38,3 @@ const pid = (' ' + proxess.pid).substr(-6); | ||
const createDebugFunction = (prefix = 'DEBUG:') => (...args) => { | ||
Number(prefix); | ||
const | ||
@@ -49,24 +50,38 @@ err = new Error(''), | ||
const raw = (string) => { proxess.stdout.write(string); }; | ||
const trace = LOG_LEVEL > levels.trace ? noop : createDebugFunction('TRACE:'); | ||
const debug = LOG_LEVEL > levels.debug ? noop : createDebugFunction('DEBUG:'); | ||
const info = LOG_LEVEL > levels.info ? noop : (...args) => { _log(jsonDate(), 'INFO:', ...args); }; | ||
const warn = LOG_LEVEL > levels.warn ? noop : (...args) => { _warn(jsonDate(), 'WARN:', ...args); }; | ||
const error = LOG_LEVEL > levels.error ? noop : (...args) => { _err(jsonDate(), 'ERROR:', ...args); }; | ||
const fatal = (...args) => { _err(jsonDate(), 'FATAL:', ...args); }; | ||
// eslint-disable-next-line no-confusing-arrow | ||
const getPrefix = _prefix => _prefix ? `${_prefix} ` : ''; | ||
module.exports = { | ||
raw, | ||
pid, | ||
jsonDate, | ||
trace, | ||
debug, | ||
info, | ||
log: info, // this is here just to help a smooth transition from console.log | ||
warn, | ||
error, | ||
fatal, | ||
LOG_LEVEL, | ||
get levels() { return JSON.parse(JSON.stringify(levels)); }, | ||
const createLogger = (_prefix) => { | ||
const prefix = getPrefix(_prefix); | ||
const trace = LOG_LEVEL > levels.trace ? noop : createDebugFunction(`${prefix}TRACE:`); | ||
const debug = LOG_LEVEL > levels.debug ? noop : createDebugFunction(`${prefix}DEBUG:`); | ||
const info = LOG_LEVEL > levels.info ? noop : (...args) => { _log(jsonDate(), `${prefix}INFO:`, ...args); }; | ||
const warn = LOG_LEVEL > levels.warn ? noop : (...args) => { _warn(jsonDate(), `${prefix}WARN:`, ...args); }; | ||
const error = LOG_LEVEL > levels.error ? noop : (...args) => { _err(jsonDate(), `${prefix}ERROR:`, ...args); }; | ||
const fatal = (...args) => { _err(jsonDate(), `${prefix}FATAL:`, ...args); }; | ||
const newLogr = { | ||
raw, | ||
pid, | ||
jsonDate, | ||
trace, | ||
debug, | ||
info, | ||
log: info, // this is here just to help a smooth transition from console.log | ||
warn, | ||
error, | ||
fatal, | ||
LOG_LEVEL, | ||
get levels() { return JSON.parse(JSON.stringify(levels)); }, | ||
getPrefix, | ||
createLogger, | ||
}; | ||
return newLogr; | ||
}; | ||
module.exports = createLogger(); |
{ | ||
"name": "@everymundo/simple-logr", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A very simplistic logger that allows one to avoid using the console.log directly allowing stubbing and better linting.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -122,2 +122,26 @@ 'use strict'; | ||
describe('getPrefix', () => { | ||
const { getPrefix } = cleanrequire('../index.js'); | ||
context('When a prefix is passed', () => { | ||
it('should return the same string plus a space character', () => { | ||
const prefix = 'Anything'; | ||
const res = getPrefix(prefix); | ||
const expected = `${prefix} `; | ||
expect(res).to.equal(expected); | ||
}); | ||
}); | ||
context('When NO prefix is passed', () => { | ||
it('should return an empty string', () => { | ||
const prefix = String(); | ||
const res = getPrefix(prefix); | ||
const expected = ''; | ||
expect(res).to.equal(expected); | ||
}); | ||
}); | ||
}); | ||
describe('#TRACE', () => { | ||
@@ -124,0 +148,0 @@ context('When LOG_LEVEL=trace', () => { |
Sorry, the diff of this file is not supported yet
37075
689