You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.9 KiB

  1. 'use strict'
  2. module.exports = (isDebug, processName) => {
  3. let winston = require('winston')
  4. if (typeof processName === 'undefined') {
  5. processName = 'SERVER'
  6. }
  7. // Console
  8. let logger = new (winston.Logger)({
  9. level: (isDebug) ? 'debug' : 'info',
  10. transports: [
  11. new (winston.transports.Console)({
  12. level: (isDebug) ? 'debug' : 'info',
  13. prettyPrint: true,
  14. colorize: true,
  15. silent: false,
  16. timestamp: true
  17. })
  18. ]
  19. })
  20. logger.filters.push((level, msg) => {
  21. return '[' + processName + '] ' + msg
  22. })
  23. // External services
  24. if (appconfig.externalLogging.bugsnag) {
  25. const bugsnagTransport = require('./winston-transports/bugsnag')
  26. logger.add(bugsnagTransport, {
  27. level: 'warn',
  28. key: appconfig.externalLogging.bugsnag
  29. })
  30. }
  31. if (appconfig.externalLogging.loggly) {
  32. require('winston-loggly-bulk')
  33. logger.add(winston.transports.Loggly, {
  34. token: appconfig.externalLogging.loggly.token,
  35. subdomain: appconfig.externalLogging.loggly.subdomain,
  36. tags: ['wiki-js'],
  37. level: 'warn',
  38. json: true
  39. })
  40. }
  41. if (appconfig.externalLogging.papertrail) {
  42. require('winston-papertrail').Papertrail // eslint-disable-line no-unused-expressions
  43. logger.add(winston.transports.Papertrail, {
  44. host: appconfig.externalLogging.papertrail.host,
  45. port: appconfig.externalLogging.papertrail.port,
  46. level: 'warn',
  47. program: 'wiki.js'
  48. })
  49. }
  50. if (appconfig.externalLogging.rollbar) {
  51. const rollbarTransport = require('./winston-transports/rollbar')
  52. logger.add(rollbarTransport, {
  53. level: 'warn',
  54. key: appconfig.externalLogging.rollbar
  55. })
  56. }
  57. if (appconfig.externalLogging.sentry) {
  58. const sentryTransport = require('./winston-transports/sentry')
  59. logger.add(sentryTransport, {
  60. level: 'warn',
  61. key: appconfig.externalLogging.sentry
  62. })
  63. }
  64. return logger
  65. }