enable to customize logger in the replayer (#1111)
This commit is contained in:
@@ -184,6 +184,7 @@ export class Replayer {
|
||||
pauseAnimation: true,
|
||||
mouseTail: defaultMouseTailConfig,
|
||||
useVirtualDom: true, // Virtual-dom optimization is enabled by default.
|
||||
logger: console,
|
||||
};
|
||||
this.config = Object.assign({}, defaultConfig, config);
|
||||
|
||||
@@ -269,9 +270,7 @@ export class Replayer {
|
||||
);
|
||||
value.node = realNode;
|
||||
} catch (error) {
|
||||
if (this.config.showWarning) {
|
||||
console.warn(error);
|
||||
}
|
||||
this.warn(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -495,7 +494,7 @@ export class Replayer {
|
||||
}
|
||||
|
||||
public resume(timeOffset = 0) {
|
||||
console.warn(
|
||||
this.warn(
|
||||
`The 'resume' was deprecated in 1.0. Please use 'play' method which has the same interface.`,
|
||||
);
|
||||
this.play(timeOffset);
|
||||
@@ -753,10 +752,10 @@ export class Replayer {
|
||||
isSync = false,
|
||||
) {
|
||||
if (!this.iframe.contentDocument) {
|
||||
return console.warn('Looks like your replayer has been destroyed.');
|
||||
return this.warn('Looks like your replayer has been destroyed.');
|
||||
}
|
||||
if (Object.keys(this.legacy_missingNodeRetryMap).length) {
|
||||
console.warn(
|
||||
this.warn(
|
||||
'Found unresolved missing node map',
|
||||
this.legacy_missingNodeRetryMap,
|
||||
);
|
||||
@@ -1252,12 +1251,10 @@ export class Replayer {
|
||||
mediaEl.playbackRate = d.playbackRate;
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.config.showWarning) {
|
||||
console.warn(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions
|
||||
`Failed to replay media interactions: ${error.message || error}`,
|
||||
);
|
||||
}
|
||||
this.warn(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions
|
||||
`Failed to replay media interactions: ${error.message || error}`,
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1314,9 +1311,7 @@ export class Replayer {
|
||||
);
|
||||
this.iframe.contentDocument?.fonts.add(fontFace);
|
||||
} catch (error) {
|
||||
if (this.config.showWarning) {
|
||||
console.warn(error);
|
||||
}
|
||||
this.warn(error);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1354,9 +1349,7 @@ export class Replayer {
|
||||
);
|
||||
if (virtualNode) value.node = virtualNode;
|
||||
} catch (error) {
|
||||
if (this.config.showWarning) {
|
||||
console.warn(error);
|
||||
}
|
||||
this.warn(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1437,7 +1430,7 @@ export class Replayer {
|
||||
|
||||
const appendNode = (mutation: addedNodeMutation) => {
|
||||
if (!this.iframe.contentDocument) {
|
||||
return console.warn('Looks like your replayer has been destroyed.');
|
||||
return this.warn('Looks like your replayer has been destroyed.');
|
||||
}
|
||||
let parent: Node | null | ShadowRoot | RRNode = mirror.getNode(
|
||||
mutation.parentId,
|
||||
@@ -1718,12 +1711,10 @@ export class Replayer {
|
||||
value,
|
||||
);
|
||||
} catch (error) {
|
||||
if (this.config.showWarning) {
|
||||
console.warn(
|
||||
'An error occurred may due to the checkout feature.',
|
||||
error,
|
||||
);
|
||||
}
|
||||
this.warn(
|
||||
'An error occurred may due to the checkout feature.',
|
||||
error,
|
||||
);
|
||||
}
|
||||
} else if (attributeName === 'style') {
|
||||
const styleValues = value;
|
||||
@@ -2136,20 +2127,20 @@ export class Replayer {
|
||||
* is microtask, so events fired on a removed DOM may emit
|
||||
* snapshots in the reverse order.
|
||||
*/
|
||||
this.debug(REPLAY_CONSOLE_PREFIX, `Node with id '${id}' not found. `, d);
|
||||
this.debug(`Node with id '${id}' not found. `, d);
|
||||
}
|
||||
|
||||
private warn(...args: Parameters<typeof console.warn>) {
|
||||
if (!this.config.showWarning) {
|
||||
return;
|
||||
}
|
||||
console.warn(REPLAY_CONSOLE_PREFIX, ...args);
|
||||
this.config.logger.warn(REPLAY_CONSOLE_PREFIX, ...args);
|
||||
}
|
||||
|
||||
private debug(...args: Parameters<typeof console.log>) {
|
||||
if (!this.config.showDebug) {
|
||||
return;
|
||||
}
|
||||
console.log(REPLAY_CONSOLE_PREFIX, ...args);
|
||||
this.config.logger.log(REPLAY_CONSOLE_PREFIX, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +180,10 @@ export type playerConfig = {
|
||||
};
|
||||
unpackFn?: UnpackFn;
|
||||
useVirtualDom: boolean;
|
||||
logger: {
|
||||
log: (...args: Parameters<typeof console.log>) => void;
|
||||
warn: (...args: Parameters<typeof console.warn>) => void;
|
||||
};
|
||||
plugins?: ReplayPlugin[];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user