logger.js 923 B

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