logstash.js 757 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const format = require('./format');
  3. const { MESSAGE } = require('triple-beam');
  4. const jsonStringify = require('fast-safe-stringify');
  5. /*
  6. * function logstash (info)
  7. * Returns a new instance of the LogStash Format that turns a
  8. * log `info` object into pure JSON with the appropriate logstash
  9. * options. This was previously exposed as { logstash: true }
  10. * to transports in `winston < 3.0.0`.
  11. */
  12. module.exports = format(info => {
  13. const logstash = {};
  14. if (info.message) {
  15. logstash['@message'] = info.message;
  16. delete info.message;
  17. }
  18. if (info.timestamp) {
  19. logstash['@timestamp'] = info.timestamp;
  20. delete info.timestamp;
  21. }
  22. logstash['@fields'] = info;
  23. info[MESSAGE] = jsonStringify(logstash);
  24. return info;
  25. });