upgrade to esm from @std/esm

make export into a function that accepts opts and returns logger child
master
David Kebler 2018-05-16 07:17:49 -07:00
parent f327fd57ae
commit fa71401fb8
4 changed files with 40 additions and 360 deletions

332
package-lock.json generated
View File

@ -1,332 +0,0 @@
{
"name": "@uci/logger",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"ansi-regex": {
"version": "2.1.1",
"resolved": "http://trantor:8082/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8="
},
"ansi-styles": {
"version": "3.2.0",
"resolved": "http://trantor:8082/ansi-styles/-/ansi-styles-3.2.0.tgz",
"integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==",
"requires": {
"color-convert": "1.9.1"
}
},
"chalk": {
"version": "2.3.0",
"resolved": "http://trantor:8082/chalk/-/chalk-2.3.0.tgz",
"integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==",
"requires": {
"ansi-styles": "3.2.0",
"escape-string-regexp": "1.0.5",
"supports-color": "4.5.0"
}
},
"color-convert": {
"version": "1.9.1",
"resolved": "http://trantor:8082/color-convert/-/color-convert-1.9.1.tgz",
"integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==",
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "http://trantor:8082/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
},
"core-util-is": {
"version": "1.0.2",
"resolved": "http://trantor:8082/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"end-of-stream": {
"version": "1.4.1",
"resolved": "http://trantor:8082/end-of-stream/-/end-of-stream-1.4.1.tgz",
"integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==",
"requires": {
"once": "1.4.0"
}
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "http://trantor:8082/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
},
"fast-json-parse": {
"version": "1.0.3",
"resolved": "http://trantor:8082/fast-json-parse/-/fast-json-parse-1.0.3.tgz",
"integrity": "sha512-FRWsaZRWEJ1ESVNbDWmsAlqDk96gPQezzLghafp5J4GUKjbCz3OkAHuZs5TuPEtkbVQERysLp9xv6c24fBm8Aw=="
},
"fast-safe-stringify": {
"version": "1.2.3",
"resolved": "http://trantor:8082/fast-safe-stringify/-/fast-safe-stringify-1.2.3.tgz",
"integrity": "sha512-QJYT/i0QYoiZBQ71ivxdyTqkwKkQ0oxACXHYxH2zYHJEgzi2LsbjgvtzTbLi1SZcF190Db2YP7I7eTsU2egOlw=="
},
"flatstr": {
"version": "1.0.5",
"resolved": "http://trantor:8082/flatstr/-/flatstr-1.0.5.tgz",
"integrity": "sha1-W0UbCMvUji6sVKK74L9GFlqhS+M="
},
"has-ansi": {
"version": "2.0.0",
"resolved": "http://trantor:8082/has-ansi/-/has-ansi-2.0.0.tgz",
"integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=",
"requires": {
"ansi-regex": "2.1.1"
}
},
"has-flag": {
"version": "2.0.0",
"resolved": "http://trantor:8082/has-flag/-/has-flag-2.0.0.tgz",
"integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE="
},
"inherits": {
"version": "2.0.3",
"resolved": "http://trantor:8082/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"is-finite": {
"version": "1.0.2",
"resolved": "http://trantor:8082/is-finite/-/is-finite-1.0.2.tgz",
"integrity": "sha1-zGZ3aVYCvlUO8R6LSqYwU0K20Ko=",
"requires": {
"number-is-nan": "1.0.1"
}
},
"isarray": {
"version": "1.0.0",
"resolved": "http://trantor:8082/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"moment": {
"version": "2.20.1",
"resolved": "http://trantor:8082/moment/-/moment-2.20.1.tgz",
"integrity": "sha512-Yh9y73JRljxW5QxN08Fner68eFLxM5ynNOAw2LbIB1YAGeQzZT8QFSUvkAz609Zf+IHhhaUxqZK8dG3W/+HEvg=="
},
"number-is-nan": {
"version": "1.0.1",
"resolved": "http://trantor:8082/number-is-nan/-/number-is-nan-1.0.1.tgz",
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0="
},
"once": {
"version": "1.4.0",
"resolved": "http://trantor:8082/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"requires": {
"wrappy": "1.0.2"
}
},
"pad-left": {
"version": "2.1.0",
"resolved": "http://trantor:8082/pad-left/-/pad-left-2.1.0.tgz",
"integrity": "sha1-FuajstRKjhOMsIOMx8tAOk/J6ZQ=",
"requires": {
"repeat-string": "1.6.1"
}
},
"pad-right": {
"version": "0.2.2",
"resolved": "http://trantor:8082/pad-right/-/pad-right-0.2.2.tgz",
"integrity": "sha1-b7ySQEXSRPKiokRQMGDTv8YAl3Q=",
"requires": {
"repeat-string": "1.6.1"
}
},
"parse-ms": {
"version": "1.0.1",
"resolved": "http://trantor:8082/parse-ms/-/parse-ms-1.0.1.tgz",
"integrity": "sha1-VjRtR0nXjyNDDKDHE4UK75GqNh0="
},
"pino": {
"version": "4.10.3",
"resolved": "http://trantor:8082/pino/-/pino-4.10.3.tgz",
"integrity": "sha512-IKXK0dcFQYITgOJBEvy1RCI5gUz+VVERXMhIvk5Ie+k9zzrbwXDs38M3H6JhoCHR58exyNpNcEKBrW4JC2P0pg==",
"requires": {
"chalk": "2.3.0",
"fast-json-parse": "1.0.3",
"fast-safe-stringify": "1.2.3",
"flatstr": "1.0.5",
"pump": "2.0.1",
"quick-format-unescaped": "1.1.2",
"split2": "2.2.0"
}
},
"pino-colada": {
"version": "1.4.2",
"resolved": "http://trantor:8082/pino-colada/-/pino-colada-1.4.2.tgz",
"integrity": "sha1-pLTX4a/pVCXrxmXagYxSZgAtEyQ=",
"requires": {
"chalk": "2.3.0",
"fast-json-parse": "1.0.3",
"pad-left": "2.1.0",
"pad-right": "0.2.2",
"prettier-bytes": "1.0.4",
"pretty-ms": "2.1.0",
"split2": "2.2.0"
}
},
"pino-pretty-minimist": {
"version": "0.3.0",
"resolved": "http://trantor:8082/pino-pretty-minimist/-/pino-pretty-minimist-0.3.0.tgz",
"integrity": "sha1-GqKCaUOx+/GuCcKpVDDB0VABrWs=",
"requires": {
"chalk": "1.1.3",
"fast-json-parse": "1.0.3",
"moment": "2.20.1",
"split2": "2.2.0"
},
"dependencies": {
"ansi-styles": {
"version": "2.2.1",
"resolved": "http://trantor:8082/ansi-styles/-/ansi-styles-2.2.1.tgz",
"integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4="
},
"chalk": {
"version": "1.1.3",
"resolved": "http://trantor:8082/chalk/-/chalk-1.1.3.tgz",
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
"requires": {
"ansi-styles": "2.2.1",
"escape-string-regexp": "1.0.5",
"has-ansi": "2.0.0",
"strip-ansi": "3.0.1",
"supports-color": "2.0.0"
}
},
"supports-color": {
"version": "2.0.0",
"resolved": "http://trantor:8082/supports-color/-/supports-color-2.0.0.tgz",
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc="
}
}
},
"plur": {
"version": "1.0.0",
"resolved": "http://trantor:8082/plur/-/plur-1.0.0.tgz",
"integrity": "sha1-24XGgU9eXlo7Se/CjWBP7GKXUVY="
},
"prettier-bytes": {
"version": "1.0.4",
"resolved": "http://trantor:8082/prettier-bytes/-/prettier-bytes-1.0.4.tgz",
"integrity": "sha1-mUsCqkb2mcULYle1+qp/4lV+YtY="
},
"pretty-ms": {
"version": "2.1.0",
"resolved": "http://trantor:8082/pretty-ms/-/pretty-ms-2.1.0.tgz",
"integrity": "sha1-QlfCVt8/sLRR1q/6qwIYhBJpgdw=",
"requires": {
"is-finite": "1.0.2",
"parse-ms": "1.0.1",
"plur": "1.0.0"
}
},
"process-nextick-args": {
"version": "1.0.7",
"resolved": "http://trantor:8082/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
"integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M="
},
"pump": {
"version": "2.0.1",
"resolved": "http://trantor:8082/pump/-/pump-2.0.1.tgz",
"integrity": "sha512-ruPMNRkN3MHP1cWJc9OWr+T/xDP0jhXYCLfJcBuX54hhfIBnaQmAUMfDcG4DM5UMWByBbJY69QSphm3jtDKIkA==",
"requires": {
"end-of-stream": "1.4.1",
"once": "1.4.0"
}
},
"quick-format-unescaped": {
"version": "1.1.2",
"resolved": "http://trantor:8082/quick-format-unescaped/-/quick-format-unescaped-1.1.2.tgz",
"integrity": "sha1-DKWB3jF0vs7yWsPC6JVjQjgdtpg=",
"requires": {
"fast-safe-stringify": "1.2.3"
}
},
"readable-stream": {
"version": "2.3.3",
"resolved": "http://trantor:8082/readable-stream/-/readable-stream-2.3.3.tgz",
"integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==",
"requires": {
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "1.0.0",
"process-nextick-args": "1.0.7",
"safe-buffer": "5.1.1",
"string_decoder": "1.0.3",
"util-deprecate": "1.0.2"
}
},
"repeat-string": {
"version": "1.6.1",
"resolved": "http://trantor:8082/repeat-string/-/repeat-string-1.6.1.tgz",
"integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc="
},
"safe-buffer": {
"version": "5.1.1",
"resolved": "http://trantor:8082/safe-buffer/-/safe-buffer-5.1.1.tgz",
"integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="
},
"split2": {
"version": "2.2.0",
"resolved": "http://trantor:8082/split2/-/split2-2.2.0.tgz",
"integrity": "sha512-RAb22TG39LhI31MbreBgIuKiIKhVsawfTgEGqKHTK87aG+ul/PB8Sqoi3I7kVdRWiCfrKxK3uo4/YUkpNvhPbw==",
"requires": {
"through2": "2.0.3"
}
},
"string_decoder": {
"version": "1.0.3",
"resolved": "http://trantor:8082/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
"requires": {
"safe-buffer": "5.1.1"
}
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "http://trantor:8082/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"requires": {
"ansi-regex": "2.1.1"
}
},
"supports-color": {
"version": "4.5.0",
"resolved": "http://trantor:8082/supports-color/-/supports-color-4.5.0.tgz",
"integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=",
"requires": {
"has-flag": "2.0.0"
}
},
"through2": {
"version": "2.0.3",
"resolved": "http://trantor:8082/through2/-/through2-2.0.3.tgz",
"integrity": "sha1-AARWmzfHx0ujnEPzzteNGtlBQL4=",
"requires": {
"readable-stream": "2.3.3",
"xtend": "4.0.1"
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "http://trantor:8082/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"wrappy": {
"version": "1.0.2",
"resolved": "http://trantor:8082/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"xtend": {
"version": "4.0.1",
"resolved": "http://trantor:8082/xtend/-/xtend-4.0.1.tgz",
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
}
}
}

View File

@ -1,14 +1,14 @@
{ {
"name": "@uci/logger", "name": "@uci/logger",
"version": "0.0.1", "version": "0.0.3",
"description": "Parent Logger for all UCI modules", "description": "Parent Logger for all UCI modules",
"main": "src/logger", "main": "src/logger",
"scripts": { "scripts": {
"testw": "mocha -r @std/esm test/*.test.mjs --watch --recurse --watch-extensions mjs", "testw": "mocha -r esmtest/*.test.mjs --watch --recurse --watch-extensions mjs",
"test": "mocha -r @std/esm test/*.test.mjs", "test": "mocha -r esmtest/*.test.mjs",
"testci": "istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -R spec --recursive && codecov || true", "testci": "istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -R spec --recursive && codecov || true",
"example": "node -r @std/esm example/example", "example": "node -r esm example/example",
"dev": "./node_modules/.bin/nodemon -r @std/esm -e mjs example/example" "dev": "./node_modules/.bin/nodemon -r esm-e mjs example/example"
}, },
"author": "David Kebler", "author": "David Kebler",
"license": "MIT", "license": "MIT",
@ -28,9 +28,8 @@
"dependencies": { "dependencies": {
"pino": "^4.10.3" "pino": "^4.10.3"
}, },
"@std/esm": "cjs",
"devDependencies": { "devDependencies": {
"@std/esm": "^0.18.0",
"nodemon": "^1.14.3", "nodemon": "^1.14.3",
"chai": "^4.1.2", "chai": "^4.1.2",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",

34
src/logger.js Normal file
View File

@ -0,0 +1,34 @@
import pino from 'pino'
let pretty = null
if(process.env.UCI_DEV || process.env.DEBUG) {
pretty = pino.pretty()
pretty.pipe(process.stdout)
}
let LOG = process.env.UCI_LOG || process.env.UCI_DEV || process.env.DEBUG
const logger = pino({
name: 'UCI',
enabled: !!LOG,
safe: true,
serializers: {
req: pino.stdSerializers.req,
res: pino.stdSerializers.res
}
},pretty)
function child (opts) {
const LOG_OPTS = {
repo: opts.repo || 'uci-'+ opts.name,
package: opts.package || '@uci/'+ opts.name,
file: opts.file || `src/${opts.name}.js`,
class: opts.class || (opts.name.charAt(0).toUpperCase() + opts.name.slice(1)),
id: opts.id || opts.name || 'none',
instance_created:new Date().getTime()
}
return logger.child(LOG_OPTS)
}
export default child

View File

@ -1,21 +0,0 @@
import pino from 'pino'
let pretty = null
if(process.env.UCI_DEV || process.env.DEBUG) {
pretty = pino.pretty()
pretty.pipe(process.stdout)
}
let LOG = process.env.UCI_LOG || process.env.UCI_DEV || process.env.DEBUG
const logger = pino({
name: 'UCI',
enabled: !!LOG,
safe: true,
serializers: {
req: pino.stdSerializers.req,
res: pino.stdSerializers.res
}
},pretty)
export default logger