logger.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * INFO level log
  3. * @param {string} msg the message to log
  4. * @param {string=} tag a unique tag to easily search for this message
  5. */
  6. exports.info = (msg, tag) => {
  7. log(msg, tag, 'info')
  8. }
  9. /**
  10. * WARN level log
  11. * @param {string} msg the message to log
  12. * @param {string=} tag a unique tag to easily search for this message
  13. */
  14. exports.warn = (msg, tag) => {
  15. log(msg, tag, 'warn')
  16. }
  17. /**
  18. * ERROR level log
  19. * @param {string | Error} msg the message to log
  20. * @param {string=} tag a unique tag to easily search for this message
  21. */
  22. exports.error = (msg, tag) => {
  23. log(msg, tag, 'error')
  24. }
  25. /**
  26. * DEBUG level log
  27. * @param {string} msg the message to log
  28. * @param {string=} tag a unique tag to easily search for this message
  29. */
  30. exports.debug = (msg, tag) => {
  31. if (process.env.NODE_ENV !== 'production') {
  32. log(msg, tag, 'debug')
  33. }
  34. }
  35. /**
  36. * message log
  37. * @param {string | Error} msg the message to log
  38. * @param {string} tag a unique tag to easily search for this message
  39. * @param {string} level error | info | debug
  40. */
  41. const log = (msg, tag, level) => {
  42. // @TODO add some colors based on log level
  43. const time = new Date().toISOString()
  44. // exclude msg from template string so values such as error objects
  45. // can be well formatted
  46. console.log(`uppy: ${time} [${level}] ${tag || ''}`, msg)
  47. }