enable to customize logger in the replayer (#1111)
This commit is contained in:
1
guide.md
1
guide.md
@@ -311,6 +311,7 @@ The replayer accepts options as its constructor's second parameter, and it has t
|
|||||||
| logConfig | - | configuration of console output playback, refer to the [console recipe](./docs/recipes/console.md) |
|
| logConfig | - | configuration of console output playback, refer to the [console recipe](./docs/recipes/console.md) |
|
||||||
| plugins | [] | load plugins to provide extended replay functions. [What is plugins?](./docs/recipes/plugin.md) |
|
| plugins | [] | load plugins to provide extended replay functions. [What is plugins?](./docs/recipes/plugin.md) |
|
||||||
| useVirtualDom | true | whether to use Virtual Dom optimization in the process of skipping to a new point of time |
|
| useVirtualDom | true | whether to use Virtual Dom optimization in the process of skipping to a new point of time |
|
||||||
|
| logger | console | The logger object used by the replayer to print warnings or errors |
|
||||||
|
|
||||||
#### Use rrweb-player
|
#### Use rrweb-player
|
||||||
|
|
||||||
|
|||||||
@@ -306,6 +306,7 @@ replayer.destroy();
|
|||||||
| unpackFn | - | 数据解压缩函数,详见[优化存储策略](./docs/recipes/optimize-storage.zh_CN.md) |
|
| unpackFn | - | 数据解压缩函数,详见[优化存储策略](./docs/recipes/optimize-storage.zh_CN.md) |
|
||||||
| plugins | [] | 加载插件以获得额外的回放功能. [什么是插件?](./docs/recipes/plugin.zh_CN.md) |
|
| plugins | [] | 加载插件以获得额外的回放功能. [什么是插件?](./docs/recipes/plugin.zh_CN.md) |
|
||||||
| useVirtualDom | true | 在播放器跳转到一个新的时间点的过程中,是否使用 Virtual Dom 优化 |
|
| useVirtualDom | true | 在播放器跳转到一个新的时间点的过程中,是否使用 Virtual Dom 优化 |
|
||||||
|
| logger | console | 当播放器出现警告或错误时用来打印日志的对象 |
|
||||||
|
|
||||||
#### 使用 rrweb-player
|
#### 使用 rrweb-player
|
||||||
|
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ export class Replayer {
|
|||||||
pauseAnimation: true,
|
pauseAnimation: true,
|
||||||
mouseTail: defaultMouseTailConfig,
|
mouseTail: defaultMouseTailConfig,
|
||||||
useVirtualDom: true, // Virtual-dom optimization is enabled by default.
|
useVirtualDom: true, // Virtual-dom optimization is enabled by default.
|
||||||
|
logger: console,
|
||||||
};
|
};
|
||||||
this.config = Object.assign({}, defaultConfig, config);
|
this.config = Object.assign({}, defaultConfig, config);
|
||||||
|
|
||||||
@@ -269,9 +270,7 @@ export class Replayer {
|
|||||||
);
|
);
|
||||||
value.node = realNode;
|
value.node = realNode;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.config.showWarning) {
|
this.warn(error);
|
||||||
console.warn(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -495,7 +494,7 @@ export class Replayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public resume(timeOffset = 0) {
|
public resume(timeOffset = 0) {
|
||||||
console.warn(
|
this.warn(
|
||||||
`The 'resume' was deprecated in 1.0. Please use 'play' method which has the same interface.`,
|
`The 'resume' was deprecated in 1.0. Please use 'play' method which has the same interface.`,
|
||||||
);
|
);
|
||||||
this.play(timeOffset);
|
this.play(timeOffset);
|
||||||
@@ -753,10 +752,10 @@ export class Replayer {
|
|||||||
isSync = false,
|
isSync = false,
|
||||||
) {
|
) {
|
||||||
if (!this.iframe.contentDocument) {
|
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) {
|
if (Object.keys(this.legacy_missingNodeRetryMap).length) {
|
||||||
console.warn(
|
this.warn(
|
||||||
'Found unresolved missing node map',
|
'Found unresolved missing node map',
|
||||||
this.legacy_missingNodeRetryMap,
|
this.legacy_missingNodeRetryMap,
|
||||||
);
|
);
|
||||||
@@ -1252,12 +1251,10 @@ export class Replayer {
|
|||||||
mediaEl.playbackRate = d.playbackRate;
|
mediaEl.playbackRate = d.playbackRate;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.config.showWarning) {
|
this.warn(
|
||||||
console.warn(
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions
|
`Failed to replay media interactions: ${error.message || error}`,
|
||||||
`Failed to replay media interactions: ${error.message || error}`,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1314,9 +1311,7 @@ export class Replayer {
|
|||||||
);
|
);
|
||||||
this.iframe.contentDocument?.fonts.add(fontFace);
|
this.iframe.contentDocument?.fonts.add(fontFace);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.config.showWarning) {
|
this.warn(error);
|
||||||
console.warn(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1354,9 +1349,7 @@ export class Replayer {
|
|||||||
);
|
);
|
||||||
if (virtualNode) value.node = virtualNode;
|
if (virtualNode) value.node = virtualNode;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.config.showWarning) {
|
this.warn(error);
|
||||||
console.warn(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1437,7 +1430,7 @@ export class Replayer {
|
|||||||
|
|
||||||
const appendNode = (mutation: addedNodeMutation) => {
|
const appendNode = (mutation: addedNodeMutation) => {
|
||||||
if (!this.iframe.contentDocument) {
|
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(
|
let parent: Node | null | ShadowRoot | RRNode = mirror.getNode(
|
||||||
mutation.parentId,
|
mutation.parentId,
|
||||||
@@ -1718,12 +1711,10 @@ export class Replayer {
|
|||||||
value,
|
value,
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (this.config.showWarning) {
|
this.warn(
|
||||||
console.warn(
|
'An error occurred may due to the checkout feature.',
|
||||||
'An error occurred may due to the checkout feature.',
|
error,
|
||||||
error,
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (attributeName === 'style') {
|
} else if (attributeName === 'style') {
|
||||||
const styleValues = value;
|
const styleValues = value;
|
||||||
@@ -2136,20 +2127,20 @@ export class Replayer {
|
|||||||
* is microtask, so events fired on a removed DOM may emit
|
* is microtask, so events fired on a removed DOM may emit
|
||||||
* snapshots in the reverse order.
|
* 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>) {
|
private warn(...args: Parameters<typeof console.warn>) {
|
||||||
if (!this.config.showWarning) {
|
if (!this.config.showWarning) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.warn(REPLAY_CONSOLE_PREFIX, ...args);
|
this.config.logger.warn(REPLAY_CONSOLE_PREFIX, ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private debug(...args: Parameters<typeof console.log>) {
|
private debug(...args: Parameters<typeof console.log>) {
|
||||||
if (!this.config.showDebug) {
|
if (!this.config.showDebug) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(REPLAY_CONSOLE_PREFIX, ...args);
|
this.config.logger.log(REPLAY_CONSOLE_PREFIX, ...args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,6 +180,10 @@ export type playerConfig = {
|
|||||||
};
|
};
|
||||||
unpackFn?: UnpackFn;
|
unpackFn?: UnpackFn;
|
||||||
useVirtualDom: boolean;
|
useVirtualDom: boolean;
|
||||||
|
logger: {
|
||||||
|
log: (...args: Parameters<typeof console.log>) => void;
|
||||||
|
warn: (...args: Parameters<typeof console.warn>) => void;
|
||||||
|
};
|
||||||
plugins?: ReplayPlugin[];
|
plugins?: ReplayPlugin[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user