Logger improved (#521)

* Logger styles improved

Resolves #520

* increment version

* update bundle

* change last log
This commit is contained in:
Peter Savchenko 2018-11-24 12:57:11 +03:00 committed by GitHub
parent bcdfcdadbc
commit 09df079509
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 30 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "codex.editor",
"version": "2.5.0",
"version": "2.5.1",
"description": "Codex Editor. Native JS, based on API and Open Source",
"main": "build/codex-editor.js",
"types": "./types/index.d.ts",

View file

@ -75,7 +75,7 @@ export default class Core {
await this.init();
await this.start();
_.log('I\'m ready! (ノ◕ヮ◕)ノ*:・゚✧');
_.log('I\'m ready! (ノ◕ヮ◕)ノ*:・゚✧', 'log', '', 'color: #E24A75');
setTimeout(() => {
/**
@ -230,14 +230,14 @@ export default class Core {
await modulesToPrepare.reduce(
(promise, module) => promise.then(async () => {
_.log(`Preparing ${module} module`, 'time');
// _.log(`Preparing ${module} module`, 'time');
try {
await this.moduleInstances[module].prepare();
} catch (e) {
_.log(`Module ${module} was skipped because of %o`, 'warn', e);
}
_.log(`Preparing ${module} module`, 'timeEnd');
// _.log(`Preparing ${module} module`, 'timeEnd');
}),
Promise.resolve(),
);
@ -262,7 +262,7 @@ export default class Core {
config : this.configuration,
});
} catch ( e ) {
console.log('Module %o skipped because %o', Module, e);
_.log(`Module ${Module.displayName} skipped because`, 'warn', e);
}
});
}

View file

@ -4,6 +4,11 @@
import Dom from './dom';
/**
* Allow to use global VERSION, that will be overwritten by Webpack
*/
declare const VERSION: string;
/**
* @typedef {Object} ChainData
* @property {Object} data - data that will be passed to the success or fallback
@ -23,28 +28,36 @@ export default class Util {
*
* @param {string} msg - message
* @param {string} type - logging type 'log'|'warn'|'error'|'info'
* @param {*} args - argument to log with a message
* @param {*} [args] - argument to log with a message
* @param {string} style - additional styling to message
*/
public static log(msg: string, type: string = 'log', args?: any): void {
public static log(msg: string, type: string = 'log', args?: any, style: string = 'color: inherit'): void {
if (!args) {
if (['time', 'timeEnd'].includes(type)) {
msg = `[codex-editor]: ${msg}`;
} else {
args = msg || 'undefined';
msg = '[codex-editor]: %o';
}
} else {
msg = '[codex-editor]: ' + msg;
if ( !('console' in window) || !window.console[ type ] ) {
return;
}
const editorLabelText = `Editor.js ${VERSION}`;
const editorLabelStyle = `line-height: 1em;
color: #006FEA;
display: inline-block;
font-size: 11px;
line-height: 1em;
background-color: #fff;
padding: 4px 9px;
border-radius: 30px;
border: 1px solid rgba(56, 138, 229, 0.16);
margin: 4px 5px 4px 0;`;
try {
if ( 'console' in window && window.console[ type ] ) {
if ( args ) { window.console[ type ]( msg, args ); } else { window.console[ type ]( msg ); }
if (['time', 'timeEnd'].includes(type)) {
console[type](`( ${editorLabelText} ) ${msg}`);
} else if (args) {
console[type](`%c${editorLabelText}%c ${msg} %o`, editorLabelStyle, style, args);
} else {
console[type](`%c${editorLabelText}%c ${msg}`, editorLabelStyle, style);
}
} catch (e) {
// do nothing
}
} catch (ignored) {}
}
/**