pretty-print.js 1.0 KB

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