Skip to content
Permalink
Browse files

Merge branch 't/13632'

  • Loading branch information...
Reinmar committed Sep 7, 2015
2 parents b12698b + 5bc146b commit 2e699f020a35f2bb1de4a5be2f6d7fa23d99e808
Showing with 402 additions and 1 deletion.
  1. +4 −0 CHANGES.md
  2. +2 −1 core/loader.js
  3. +126 −0 core/log.js
  4. +270 −0 tests/core/log.js
@@ -3,6 +3,10 @@ CKEditor 4 Changelog

## CKEditor 4.5.4

New Features:

* [#13632](http://dev.ckeditor.com/ticket/13632): Introduce error logging mechanism.

Fixed Issues:

* [#9856](http://dev.ckeditor.com/ticket/9856): Fixed: Cannot use the native context menu together with the [Div Editing Area](http://ckeditor.com/addon/divarea) plugin. Thanks to [Mark Wade](https://github.com/mark-wade)!
@@ -28,7 +28,7 @@ if ( !CKEDITOR.loader ) {
'dom/comment', 'dom/elementpath', 'dom/text', 'dom/rangelist', 'skin'
],
'ckeditor': [
'ckeditor_basic', 'dom', 'dtd', 'dom/document', 'dom/element', 'dom/iterator', 'editor', 'event',
'ckeditor_basic', 'log', 'dom', 'dtd', 'dom/document', 'dom/element', 'dom/iterator', 'editor', 'event',
'htmldataprocessor', 'htmlparser', 'htmlparser/element', 'htmlparser/fragment', 'htmlparser/filter',
'htmlparser/basicwriter', 'template', 'tools'
],
@@ -75,6 +75,7 @@ if ( !CKEDITOR.loader ) {
'htmlparser/node': [ 'htmlparser' ],
'keystrokehandler': [ 'event' ],
'lang': [],
'log': [ 'ckeditor_basic' ],
'plugins': [ 'resourcemanager' ],
'resourcemanager': [ 'scriptloader', 'tools' ],
'scriptloader': [ 'dom/element', 'env' ],
@@ -0,0 +1,126 @@
/**
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/

/**
* @fileOverview Defines {@link CKEDITOR#verbosity} and binary flags {@link CKEDITOR#VERBOSITY_WARN} and
* {@link CKEDITOR#VERBOSITY_ERROR}. Defines also {@link CKEDITOR#error} and {@link CKEDITOR#warn} functions
* and default handler for {@link CKEDITOR#log} event.
*/

/* global console */

'use strict';

/**
* Warning reporting verbosity level. When {@link CKEDITOR#verbosity} is set to this value only {@link CKEDITOR#warn}
* messages will be outputted to the console. It is a binary flag so it might be combined with
* {@link CKEDITOR#VERBOSITY_ERROR} flag.
*
* @since 4.5.4
* @readonly
* @property {Number} [=1]
* @member CKEDITOR
*/
CKEDITOR.VERBOSITY_WARN = 1;

/**
* Error reporting verbosity level. When {@link CKEDITOR#verbosity} is set to this value only {@link CKEDITOR#error}
* messages will be outputted to the console. It is a binary flag so it might be combined with
* {@link CKEDITOR#VERBOSITY_WARN} flag.
*
* @since 4.5.4
* @readonly
* @property {Number} [=2]
* @member CKEDITOR
*/
CKEDITOR.VERBOSITY_ERROR = 2;

/**
* Verbosity of {@link CKEDITOR#error} and {@link CKEDITOR#warn} methods. Accepts binary flags
* {@link CKEDITOR#VERBOSITY_WARN} and {@link CKEDITOR#VERBOSITY_ERROR}.
*
* CKEDITOR.verbosity = 0; // No console output after CKEDITOR.warn and CKEDITOR.error methods.
* CKEDITOR.verbosity = CKEDITOR.VERBOSITY_WARN; // Console output after CKEDITOR.warn only.
* CKEDITOR.verbosity = CKEDITOR.VERBOSITY_ERROR; // Console output after CKEDITOR.error only.
* CKEDITOR.verbosity = CKEDITOR.VERBOSITY_WARN | CKEDITOR.VERBOSITY_ERROR; // Console output after both methods.
*
* Default value enables both {@link CKEDITOR#VERBOSITY_WARN} and {@link CKEDITOR#VERBOSITY_ERROR}.
*
* @since 4.5.4
* @member CKEDITOR
* @type {Number}
*/
CKEDITOR.verbosity = CKEDITOR.VERBOSITY_WARN | CKEDITOR.VERBOSITY_ERROR;

/**
* Warning reporting function. When {@link CKEDITOR#verbosity} has {@link CKEDITOR#VERBOSITY_WARN} flag set, it fires
* {@link CKEDITOR#log} event with type set to `warn`. Fired event contains also provided `errorCode` and `additionalData`.
*
* @since 4.5.4
* @member CKEDITOR
* @param {String} errorCode Error code describing reported problem.
* @param {Object} [additionalData] Additional data associated with reported problem.
*/
CKEDITOR.warn = function( errorCode, additionalData ) {
if ( CKEDITOR.verbosity & CKEDITOR.VERBOSITY_WARN ) {
CKEDITOR.fire( 'log', { type: 'warn', errorCode: errorCode, additionalData: additionalData } );
}
};

/**
* Error reporting function. When {@link CKEDITOR#verbosity} has {@link CKEDITOR#VERBOSITY_ERROR} flag set, it fires
* {@link CKEDITOR#log} event with type set to `error`. Fired event contains also provided `errorCode` and `additionalData`.
*
* @since 4.5.4
* @member CKEDITOR
* @param {String} errorCode Error code describing reported problem.
* @param {Object} [additionalData] Additional data associated with reported problem.
*/
CKEDITOR.error = function( errorCode, additionalData ) {
if ( CKEDITOR.verbosity & CKEDITOR.VERBOSITY_ERROR ) {
CKEDITOR.fire( 'log', { type: 'error', errorCode: errorCode, additionalData: additionalData } );
}
};

/**
* Fired by {@link CKEDITOR#warn} and {@link CKEDITOR#error} methods.
* Default listener logs provided information to the console.
*
* This event can be used to provide custom error/warning handler:
*
* CKEDTIOR.on( 'log', function( evt ) {
* // Cancel default listener.
* evt.cancel();
* // Log event data.
* console.log( evt.data.type, evt.data.errorCode, evt.data.additionalData );
* } );
*
* @since 4.5.4
* @event log
* @member CKEDITOR
* @param data
* @param {String} data.type Log type. Can be `error` or `warn`.
* @param {String} data.errorCode Error code describing reported problem.
* @param {Object} [data.additionalData] Additional data associated with this log event.
*/
CKEDITOR.on( 'log', function( evt ) {
if ( !window.console || !window.console.log ) {
return;
}

var type = console[ evt.data.type ] ? evt.data.type : 'log',
errorCode = evt.data.errorCode,
additionalData = evt.data.additionalData,
prefix = '[CKEDITOR] ';

if ( additionalData ) {
console[ type ]( prefix + errorCode, additionalData );
} else {
console[ type ]( prefix + errorCode );
}

// TODO: Add proper info and documentation url.
console[ type ]( prefix + 'For more information go to http://docs.ckeditor.com/' );
}, null, null, 999 );
Oops, something went wrong.

0 comments on commit 2e699f0

Please sign in to comment.
You can’t perform that action at this time.