8
0

log.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * @license Copyright (c) 2003-2016, 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. const log = {
  39. /**
  40. * Logs an error to the console.
  41. *
  42. * Read more about error logging in the {@link core.log} module.
  43. *
  44. * @param {String} message The error message in an `error-name: Error message.` format.
  45. * During the minification process the "Error message" part will be removed to limit the code size
  46. * and a link to this error documentation will be logged to the console.
  47. * @param {Object} [data] Additional data describing the error.
  48. */
  49. error( message, data ) {
  50. console.error( message, data );
  51. },
  52. /**
  53. * Logs a warning to the console.
  54. *
  55. * Read more about error logging in the {@link core.log} module.
  56. *
  57. * @param {String} message The warning message in a `warning-name: Warning message.` format.
  58. * During the minification process the "Warning message" part will be removed to limit the code size
  59. * and a link to this error documentation will be logged to the console.
  60. * @param {Object} [data] Additional data describing the warning.
  61. */
  62. warn( message, data ) {
  63. console.warn( message, data );
  64. }
  65. };
  66. export default log;