logger.js 968 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. The MIT License (MIT)
  3. Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contributors. (https://github.com/NikolaySuslov/lcs-reflector/blob/master/LICENSE.md)
  4. */
  5. var winston = require('winston');
  6. const logger = winston.createLogger({
  7. level: 'info',
  8. format: winston.format.json(),
  9. transports: [
  10. //
  11. // - Write to all logs with level `info` and below to `combined.log`
  12. // - Write all logs error (and below) to `error.log`.
  13. //
  14. new winston.transports.File({ filename: 'error.log', level: 'error' }),
  15. //new winston.transports.File({ filename: 'combined.log' })
  16. ]
  17. });
  18. //
  19. // If we're not in production then log to the `console` with the format:
  20. // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
  21. //
  22. if (process.env.NODE_ENV !== 'production') {
  23. logger.add(new winston.transports.Console({
  24. format: winston.format.simple()
  25. }));
  26. }
  27. module.exports = logger;