0.0.5 • Published 8 years ago
json-log-wrapper v0.0.5
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