8
0

log.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global 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:
  16. *
  17. * /**
  18. * * Error thrown when a plugin cannot be loaded due to JavaScript errors, lack of plugins with a given name, etc.
  19. * *
  20. * * @error plugin-load
  21. * * @param pluginName The name of the plugin that could not be loaded.
  22. * * @param moduleName The name of the module which tried to load this plugin.
  23. * * /
  24. * log.error( 'plugin-load: It was not possible to load the "{$pluginName}" plugin in module "{$moduleName}', {
  25. * pluginName: 'foo',
  26. * moduleName: 'bar'
  27. * } );
  28. *
  29. * ### Warning vs Error vs Throw
  30. *
  31. * * Whenever a potentially incorrect situation occurs, which does not directly lead to an incorrect behavior,
  32. * log a warning.
  33. * * Whenever an incorrect situation occurs, but the app may continue working (although perhaps incorrectly),
  34. * log an error.
  35. * * Whenever it's really bad and it does not make sense to continue working, throw a {@link core.CKEditorError}.
  36. *
  37. * @namespace core.log
  38. */
  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. * @method core.log.error
  50. */
  51. error( message, data ) {
  52. console.error( message, data );
  53. },
  54. /**
  55. * Logs a warning to the console.
  56. *
  57. * Read more about error logging in the {@link core.log} module.
  58. *
  59. * @param {String} message The warning message in a `warning-name: Warning message.` format.
  60. * During the minification process the "Warning message" part will be removed to limit the code size
  61. * and a link to this error documentation will be logged to the console.
  62. * @param {Object} [data] Additional data describing the warning.
  63. * @method core.log.warn
  64. */
  65. warn( message, data ) {
  66. console.warn( message, data );
  67. }
  68. };
  69. export default log;