log.js 2.7 KB

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