Fix logging option (#1302)

This commit is contained in:
MoyuScript
2017-12-11 20:23:43 +08:00
parent 9873f74cd1
commit 304af7e4f9
3 changed files with 9 additions and 5 deletions

View File

@ -2,21 +2,23 @@
'use strict';
export default class Logger {
enabled: boolean;
start: number;
id: ?string;
constructor(id: ?string, start: ?number) {
constructor(enabled: boolean, id: ?string, start: ?number) {
this.enabled = enabled;
this.start = start ? start : Date.now();
this.id = id;
}
child(id: string) {
return new Logger(id, this.start);
return new Logger(this.enabled, id, this.start);
}
// eslint-disable-next-line flowtype/no-weak-types
log(...args: any) {
if (window.console && window.console.log) {
if (this.enabled && window.console && window.console.log) {
Function.prototype.bind
.call(window.console.log, window.console)
.apply(
@ -31,7 +33,7 @@ export default class Logger {
// eslint-disable-next-line flowtype/no-weak-types
error(...args: any) {
if (window.console && window.console.error) {
if (this.enabled && window.console && window.console.error) {
Function.prototype.bind
.call(window.console.error, window.console)
.apply(

View File

@ -15,6 +15,7 @@ export type Options = {
canvas: ?HTMLCanvasElement,
foreignObjectRendering: boolean,
imageTimeout: number,
logging: boolean,
proxy: ?string,
removeContainer: ?boolean,
scale: number,
@ -37,7 +38,7 @@ const html2canvas = (element: HTMLElement, conf: ?Options): Promise<*> => {
}
const config = conf || {};
const logger = new Logger();
const logger = new Logger(typeof config.logging === 'boolean' ? config.logging : true);
if (__DEV__ && typeof config.onrendered === 'function') {
logger.error(