html2canvas/src/Logger.js

49 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-07-29 05:07:42 +03:00
/* @flow */
'use strict';
export default class Logger {
2017-12-11 15:23:43 +03:00
enabled: boolean;
2017-07-29 05:07:42 +03:00
start: number;
2017-09-11 17:36:23 +03:00
id: ?string;
2017-07-29 05:07:42 +03:00
2017-12-11 15:23:43 +03:00
constructor(enabled: boolean, id: ?string, start: ?number) {
2018-02-15 17:19:25 +03:00
this.enabled = typeof window !== 'undefined' && enabled;
2017-09-11 17:36:23 +03:00
this.start = start ? start : Date.now();
this.id = id;
}
child(id: string) {
2017-12-11 15:23:43 +03:00
return new Logger(this.enabled, id, this.start);
2017-07-29 05:07:42 +03:00
}
2017-08-01 13:51:59 +03:00
// eslint-disable-next-line flowtype/no-weak-types
2017-07-29 05:07:42 +03:00
log(...args: any) {
2017-12-11 15:23:43 +03:00
if (this.enabled && window.console && window.console.log) {
Function.prototype.bind
.call(window.console.log, window.console)
.apply(
window.console,
2017-09-11 17:36:23 +03:00
[
Date.now() - this.start + 'ms',
this.id ? `html2canvas (${this.id}):` : 'html2canvas:'
].concat([].slice.call(args, 0))
);
}
2017-07-29 05:07:42 +03:00
}
2017-08-03 19:13:20 +03:00
// eslint-disable-next-line flowtype/no-weak-types
error(...args: any) {
2017-12-11 15:23:43 +03:00
if (this.enabled && window.console && window.console.error) {
Function.prototype.bind
.call(window.console.error, window.console)
.apply(
window.console,
2017-09-11 17:36:23 +03:00
[
Date.now() - this.start + 'ms',
this.id ? `html2canvas (${this.id}):` : 'html2canvas:'
].concat([].slice.call(args, 0))
);
}
2017-08-03 19:13:20 +03:00
}
2017-07-29 05:07:42 +03:00
}