common.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * common.js: Internal helper and utility functions for winston.
  3. *
  4. * (C) 2010 Charlie Robbins
  5. * MIT LICENCE
  6. */
  7. 'use strict';
  8. const { format } = require('util');
  9. /**
  10. * Set of simple deprecation notices and a way to expose them for a set of
  11. * properties.
  12. * @type {Object}
  13. * @private
  14. */
  15. exports.warn = {
  16. deprecated(prop) {
  17. return () => {
  18. throw new Error(format('{ %s } was removed in winston@3.0.0.', prop));
  19. };
  20. },
  21. useFormat(prop) {
  22. return () => {
  23. throw new Error([
  24. format('{ %s } was removed in winston@3.0.0.', prop),
  25. 'Use a custom winston.format = winston.format(function) instead.'
  26. ].join('\n'));
  27. };
  28. },
  29. forFunctions(obj, type, props) {
  30. props.forEach(prop => {
  31. obj[prop] = exports.warn[type](prop);
  32. });
  33. },
  34. moved(obj, movedTo, prop) {
  35. function movedNotice() {
  36. return () => {
  37. throw new Error([
  38. format('winston.%s was moved in winston@3.0.0.', prop),
  39. format('Use a winston.%s instead.', movedTo)
  40. ].join('\n'));
  41. };
  42. }
  43. Object.defineProperty(obj, prop, {
  44. get: movedNotice,
  45. set: movedNotice
  46. });
  47. },
  48. forProperties(obj, type, props) {
  49. props.forEach(prop => {
  50. const notice = exports.warn[type](prop);
  51. Object.defineProperty(obj, prop, {
  52. get: notice,
  53. set: notice
  54. });
  55. });
  56. }
  57. };