pretty-print.js 899 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const inspect = require('util').inspect;
  3. const format = require('./format');
  4. const { LEVEL, MESSAGE, SPLAT } = require('triple-beam');
  5. /*
  6. * function prettyPrint (info)
  7. * Returns a new instance of the prettyPrint Format that "prettyPrint"
  8. * serializes `info` objects. This was previously exposed as
  9. * { prettyPrint: true } to transports in `winston < 3.0.0`.
  10. */
  11. module.exports = format((info, opts = {}) => {
  12. //
  13. // info[{LEVEL, MESSAGE, SPLAT}] are enumerable here. Since they
  14. // are internal, we remove them before util.inspect so they
  15. // are not printed.
  16. //
  17. const stripped = Object.assign({}, info);
  18. // Remark (indexzero): update this technique in April 2019
  19. // when node@6 is EOL
  20. delete stripped[LEVEL];
  21. delete stripped[MESSAGE];
  22. delete stripped[SPLAT];
  23. info[MESSAGE] = inspect(stripped, false, opts.depth || null, opts.colorize);
  24. return info;
  25. });