From d87fef11a4561b64d8c3f75b18efa25aa353fac9 Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Mon, 11 Dec 2017 20:23:43 +0800 Subject: [PATCH] Fix logging option (#1302) --- docs/configuration.md | 1 + src/Logger.js | 10 ++++++---- src/index.js | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index be39b75..0862495 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -17,6 +17,7 @@ These are all of the available configuration options. | canvas | `null` | Existing `canvas` element to use as a base for drawing on | foreignObjectRendering | `false` | Whether to use ForeignObject rendering if the browser supports it | imageTimeout | `15000` | Timeout for loading an image (in milliseconds). Set to `0` to disable timeout. +| logging | `true` | Enable logging for debug purposes | proxy | `null` | Url to the [proxy](/proxy/) which is to be used for loading cross-origin images. If left empty, cross-origin images won't be loaded. | removeContainer | `true` | Whether to cleanup the cloned DOM elements html2canvas creates temporarily | scale | `window.devicePixelRatio` | The scale to use for rendering. Defaults to the browsers device pixel ratio. diff --git a/src/Logger.js b/src/Logger.js index c426805..dcce28b 100644 --- a/src/Logger.js +++ b/src/Logger.js @@ -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( diff --git a/src/index.js b/src/index.js index 3dc3027..5a2ff9b 100644 --- a/src/index.js +++ b/src/index.js @@ -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(