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) {
|
|
|
|
this.enabled = 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) {
|
2017-08-06 12:37:34 +03:00
|
|
|
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-08-06 12:37:34 +03:00
|
|
|
);
|
|
|
|
}
|
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) {
|
2017-08-06 12:37:34 +03:00
|
|
|
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-06 12:37:34 +03:00
|
|
|
);
|
|
|
|
}
|
2017-08-03 19:13:20 +03:00
|
|
|
}
|
2017-07-29 05:07:42 +03:00
|
|
|
}
|