diff --git a/package.json b/package.json index d8a8906..951c100 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uci/logger", - "version": "0.0.4", + "version": "0.0.6", "description": "Parent Logger for all UCI modules", "main": "src/logger", "scripts": { @@ -8,7 +8,8 @@ "test": "mocha -r esmtest/*.test.mjs", "testci": "istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -R spec --recursive && codecov || true", "example": "node -r esm example/example", - "dev": "./node_modules/.bin/nodemon -r esm-e mjs example/example" + "dev": "UCI_DEV=true ./node_modules/.bin/nodemon -r esm example/example", + "log": "UCI_LOG=true ./node_modules/.bin/nodemon -r esm example/example" }, "author": "David Kebler", "license": "MIT", @@ -26,15 +27,16 @@ }, "homepage": "https://github.com/uCOMmandIt/uci-changeme#readme", "dependencies": { - "pino": "^4.10.3" + "pino": "^5.9.0", + "pino-pretty": "^2.4.0" }, - "devDependencies": { - "nodemon": "^1.14.3", - "chai": "^4.1.2", + "chai": "^4.2.0", "chai-as-promised": "^7.1.1", - "codecov": "^3.0.0", + "codecov": "^3.1.0", + "esm": "^3.0.84", "istanbul": "^0.4.5", - "mocha": "^4.0.1" + "mocha": "^5.2.0", + "nodemon": "^1.18.7" } } diff --git a/readme.md b/readme.md index 08155c4..e274a84 100644 --- a/readme.md +++ b/readme.md @@ -1,10 +1,17 @@ -# uCOMmandIt Template Package Repository - - -[![Build Status](https://img.shields.io/travis/uCOMmandIt/uci-pkg-template.svg?branch=master)](https://travis-ci.org/uCOMmandIt/uci-pkg-template) -[![Inline docs](http://inch-ci.org/github/uCOMmandIt/uci-pkg-template.svg?branch=master)](http://inch-ci.org/github/uCOMmandIt/uci-pkg-template) -[![Dependencies](https://img.shields.io/david/uCOMmandIt/uci-pkg-template.svg)](https://david-dm.org/uCOMmandIt/uci-pkg-template) -[![devDependencies](https://img.shields.io/david/dev/uCOMmandIt/uci-pkg-template.svg)](https://david-dm.org/uCOMmandIt/uci-pkg-template?type=dev) -[![codecov](https://img.shields.io/codecov/c/github/uCOMmandIt/uci-pkg-template/master.svg)](https://codecov.io/gh/uCOMmandIt/uci-pkg-template) +# uCOMmandIt JSON Logger runtime module logger based on pino + +run example as either + +`npm run log` +for json logging + +or for pretty output `npm run dev` + + +for search/filter use environment variable + +`UCI_LOG_SEARCH='key == `\`value\``' npm run dev` + +note: ALL search values regardless of type MUST be escaped with `` diff --git a/src/logger.js b/src/logger.js index 8db9eee..caa8aa4 100644 --- a/src/logger.js +++ b/src/logger.js @@ -1,10 +1,9 @@ import pino from 'pino' - -let pretty = null +let pretty = false if(process.env.UCI_DEV) { - pretty = pino.pretty() - pretty.pipe(process.stdout) + pretty = process.env.UCI_LOG_PRETTY || {translateTime:true, colorize:true, levelFirst:true } + pretty.search = process.env.UCI_LOG_SEARCH } let LOG = process.env.UCI_LOG || process.env.UCI_DEV @@ -16,8 +15,9 @@ const logger = pino({ serializers: { req: pino.stdSerializers.req, res: pino.stdSerializers.res - } -},pretty) + }, + prettyPrint: pretty +}) function child (opts) { const LOG_OPTS = { diff --git a/test/amodule.test.js b/test/amodule.test.js deleted file mode 100644 index fe35e74..0000000 --- a/test/amodule.test.js +++ /dev/null @@ -1,49 +0,0 @@ -import aClass from '../src' -import chai from 'chai' -import chaiAsPromised from 'chai-as-promised' - -chai.use(chaiAsPromised) -const expect = chai.expect - -describe( - 'Testing ', - function () { - hooks() - sometests() - someothertests() - }) - -//****************** TESTS ********************** -function sometests() { - it('==> test something', async function () { - - let result = await someasyncfunction() - expect(result, 'test failed').to.equal('expectedresult') - - }) -} - -function someothertests() { - it('==> test something', async function () { - - let result = await someasyncfunction() - expect(result, 'test failed').to.equal('expectedresult') - - }) -} - -function hooks() { - - before(async() => { - await someasyncfunctiontodobefore() - }) - - beforeEach(async() => { - await someasyncfunctiontodobeforeeachtest() - }) - - after(async() => { - await someasyncfunctiontodoaftereeachtest() - }) - -} diff --git a/test/apromise.test.js b/test/apromise.test.js deleted file mode 100644 index 29fd4e7..0000000 --- a/test/apromise.test.js +++ /dev/null @@ -1,19 +0,0 @@ -import changeme from '../src/changeme' -import path from 'path' -import chai from 'chai' -import chaiAsPromised from 'chai-as-promised' - -const { assert } = chai; -chai.use(chaiAsPromised); - -const expect = chai.expect - -describe('Promise Stuff - ', function () { - - it('Can test a promise', function () { - - return expect(changeme.apromise).to.eventually.equal('some promise hey') - return Promise.resolve().then(() => expect(changeme.apromise).to.eventually.equal('some promise hey')) - - }) -})