json-log-wrapper

0.0.5 • Public • Published

JSON Log Wrapper

Simple class for wrapping console statements with the following data

  • dirname
  • filename
  • cwd
  • NODE_ENV

Use:

const Log = require('json-log-wrapper)
const logger = new Log(process, 'TEST_APPLICATION_NAME')
logger.log('logging test message', { asObject: 'another arg to log' })
logger.error('error! error!')

Output:

{
  "context": {
    "appName": "TEST_APPLICATION_NAME",
    "runtime": "node",
    "filename": "/Users/thibbard/Documents/tests/json-log-wrapper/test/src",
    "cwd": "/Users/thibbard/Documents/tests/json-log-wrapper",
    "NODE_ENV": "development",
    "timestamp": "2017-11-07T17:51:34.752Z"
  },
  "detail": {
    "code": "LOG",
    "messages": [
      "logging test message",
      {
        "asObject": "another arg to log"
      }
    ]
  }
}
{
  "context": {
    "appName": "TEST_APPLICATION_NAME",
    "runtime": "node",
    "filename": "/Users/thibbard/Documents/tests/json-log-wrapper/test/src",
    "cwd": "/Users/thibbard/Documents/tests/json-log-wrapper",
    "NODE_ENV": "development",
    "timestamp": "2017-11-07T17:51:34.754Z"
  },
  "detail": {
    "code": "ERROR",
    "messages": [
      "error! error!"
    ]
  }
}

If NODE_ENV is set to production, output is minified

†Uses argv[1] not, __filename

Readme

Keywords

none

Package Sidebar

Install

npm i json-log-wrapper

Weekly Downloads

0

Version

0.0.5

License

ISC

Last publish

Collaborators

  • thomashibbard