8
0

log.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global console */
  6. /**
  7. * @module utils/log
  8. */
  9. /**
  10. * The logging module.
  11. *
  12. * This object features two functions that should be used across CKEditor code base to log errors and warnings.
  13. * Despite being an overridable interface for native `console.*` this module serves also the goal to limit the
  14. * code size of a minified CKEditor package. During minification process the messages will be shortened and
  15. * links to their documentation will be logged to the console.
  16. *
  17. * All errors and warning should be documented in the following way:
  18. *
  19. * /**
  20. * * Error thrown when a plugin cannot be loaded due to JavaScript errors, lack of plugins with a given name, etc.
  21. * *
  22. * * @error plugin-load
  23. * * @param pluginName The name of the plugin that could not be loaded.
  24. * * @param moduleName The name of the module which tried to load this plugin.
  25. * * /
  26. * log.error( 'plugin-load: It was not possible to load the "{$pluginName}" plugin in module "{$moduleName}', {
  27. * pluginName: 'foo',
  28. * moduleName: 'bar'
  29. * } );
  30. *
  31. * ### Warning vs Error vs Throw
  32. *
  33. * * Whenever a potentially incorrect situation occurs, which does not directly lead to an incorrect behavior,
  34. * log a warning.
  35. * * Whenever an incorrect situation occurs, but the app may continue working (although perhaps incorrectly),
  36. * log an error.
  37. * * Whenever it's really bad and it does not make sense to continue working, throw a {@link module:utils/ckeditorerror~CKEditorError}.
  38. *
  39. * @namespace
  40. */
  41. const log = {
  42. /**
  43. * Logs an error to the console.
  44. *
  45. * Read more about error logging in the {@link module:utils/log} module.
  46. *
  47. * @param {String} message The error message in an `error-name: Error message.` format.
  48. * During the minification process the "Error message" part will be removed to limit the code size
  49. * and a link to this error documentation will be logged to the console.
  50. * @param {Object} [data] Additional data describing the error.
  51. */
  52. error( message, data ) {
  53. console.error( message, data );
  54. },
  55. /**
  56. * Logs a warning to the console.
  57. *
  58. * Read more about error logging in the {@link module:utils/log} module.
  59. *
  60. * @param {String} message The warning message in a `warning-name: Warning message.` format.
  61. * During the minification process the "Warning message" part will be removed to limit the code size
  62. * and a link to this error documentation will be logged to the console.
  63. * @param {Object} [data] Additional data describing the warning.
  64. */
  65. warn( message, data ) {
  66. console.warn( message, data );
  67. }
  68. };
  69. export default log;