logstash.js 787 B

1234567891011121314151617181920212223242526272829303132
  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 logstash (info)
  8. * Returns a new instance of the LogStash Format that turns a
  9. * log `info` object into pure JSON with the appropriate logstash
  10. * options. This was previously exposed as { logstash: true }
  11. * to transports in `winston < 3.0.0`.
  12. */
  13. module.exports = format(function (info) {
  14. var logstash = {};
  15. if (info.message) {
  16. logstash['@message'] = info.message;
  17. delete info.message;
  18. }
  19. if (info.timestamp) {
  20. logstash['@timestamp'] = info.timestamp;
  21. delete info.timestamp;
  22. }
  23. logstash['@fields'] = info;
  24. info[MESSAGE] = jsonStringify(logstash);
  25. return info;
  26. });