json.js 727 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. var format = require('./format');
  3. var _require = require('triple-beam'),
  4. MESSAGE = _require.MESSAGE;
  5. var jsonStringify = require('fast-safe-stringify');
  6. /*
  7. * function replacer (key, value)
  8. * Handles proper stringification of Buffer output.
  9. */
  10. function replacer(key, value) {
  11. return value instanceof Buffer ? value.toString('base64') : value;
  12. }
  13. /*
  14. * function json (info)
  15. * Returns a new instance of the JSON format that turns a log `info`
  16. * object into pure JSON. This was previously exposed as { json: true }
  17. * to transports in `winston < 3.0.0`.
  18. */
  19. module.exports = format(function (info, opts) {
  20. info[MESSAGE] = jsonStringify(info, opts.replacer || replacer, opts.space);
  21. return info;
  22. });