Repository: pinojs/pino
Pull request #509 (2018-08-30 05:53:48)

Add badge for JS Standard Style


Patch:
diff --git a/README.md b/README.md
index 32d7f69..ca494f8 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 ![banner](pino-banner.png)
 
-# pino&nbsp;&nbsp;[![Build Status](https://travis-ci.org/pinojs/pino.svg?branch=master)](https://travis-ci.org/pinojs/pino)&nbsp;[![Coverage Status](https://coveralls.io/repos/github/pinojs/pino/badge.svg?branch=master)](https://coveralls.io/github/pinojs/pino?branch=master) [![TypeScript definitions on DefinitelyTyped](http://definitelytyped.org/badges/standard.svg)](http://definitelytyped.org)
+# pino&nbsp;&nbsp;[![Build Status](https://travis-ci.org/pinojs/pino.svg?branch=master)](https://travis-ci.org/pinojs/pino)&nbsp;[![Coverage Status](https://coveralls.io/repos/github/pinojs/pino/badge.svg?branch=master)](https://coveralls.io/github/pinojs/pino?branch=master) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![TypeScript definitions on DefinitelyTyped](http://definitelytyped.org/badges/standard.svg)](http://definitelytyped.org)
 
 [Very low overhead](#benchmarks) Node.js logger, inspired by Bunyan.
 
diff --git a/lib/tools.js b/lib/tools.js
index 6d3c400..439c9f4 100644
--- a/lib/tools.js
+++ b/lib/tools.js
@@ -195,10 +195,11 @@ function prettifierMetaWrapper (pretty, dest) {
 
       var lastObj = this.lastObj
       var msg = this.lastMsg
+      var errorProps = null
 
       if (lastObj instanceof Error) {
         msg = msg || lastObj.message
-        lastObj = {
+        errorProps = {
           type: 'Error',
           stack: lastObj.stack
         }
@@ -208,7 +209,7 @@ function prettifierMetaWrapper (pretty, dest) {
         level: this.lastLevel,
         msg,
         time
-      }, chindings, lastObj)
+      }, chindings, lastObj, errorProps)
 
       const serializers = this.lastLogger[serializersSym]
       const keys = Object.keys(serializers)


Test patch:
diff --git a/test/fixtures/pretty/error-props.js b/test/fixtures/pretty/error-props.js
new file mode 100644
index 0000000..32812cf
--- /dev/null
+++ b/test/fixtures/pretty/error-props.js
@@ -0,0 +1,9 @@
+global.process = { __proto__: process, pid: 123456 }
+Date.now = function () { return 1459875739796 }
+require('os').hostname = function () { return 'abcdefghijklmnopqr' }
+var pino = require(require.resolve('./../../../'))
+var log = pino({
+  prettyPrint: { errorProps: 'code,errno' }
+})
+var err = Object.assign(new Error('kaboom'), { code: 'ENOENT', errno: 1 })
+log.error(err)
diff --git a/test/pretty.test.js b/test/pretty.test.js
index 3cd505e..8905fc2 100644
--- a/test/pretty.test.js
+++ b/test/pretty.test.js
@@ -187,3 +187,18 @@ test('errors', async ({ isNot }) => {
   isNot(actual.match(/\(123456 on abcdefghijklmnopqr\): with a message/), null)
   isNot(actual.match(/.*error\.js.*/), null)
 })
+
+test('errors with props', async ({ isNot }) => {
+  var actual = ''
+  const child = fork(join(__dirname, 'fixtures', 'pretty', 'error-props.js'), { silent: true })
+
+  child.stdout.pipe(writer((s, enc, cb) => {
+    actual += s
+    cb()
+  }))
+  await once(child, 'close')
+  isNot(actual.match(/\(123456 on abcdefghijklmnopqr\): kaboom/), null)
+  isNot(actual.match(/code: ENOENT/), null)
+  isNot(actual.match(/errno: 1/), null)
+  isNot(actual.match(/.*error-props\.js.*/), null)
+})