> For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt.

# onConsoleLog

- **类型：** `(content: string, type: 'stdout' | 'stderr') => boolean | void`
- **默认值：** `undefined`

自定义 console 日志的处理函数，这有助于过滤来自第三方库的日志。

处理函数会接收到日志内容 `content` 以及它的来源流 `type`（`'stdout'` 或 `'stderr'`），因此你既能按文本过滤，也能按输出流过滤。如果你返回 `false`，Rstest 不会将此日志打印到控制台。

```ts title="rstest.config.ts"
import { defineConfig } from '@rstest/core';

export default defineConfig({
  onConsoleLog: (content, type) => {
    if (type === 'stderr' && content.includes('deprecated')) {
      return false;
    }
  },
});
```

:::note
当 [disableConsoleIntercept](/zh/config/test/disable-console-intercept.md) 为 `true` 时，`onConsoleLog` 将不会生效。
:::

## 静默控制台日志

你可以通过在 `onConsoleLog` 处理函数中返回 `false` 来静默控制台日志。

```ts title="rstest.config.ts"
import { defineConfig } from '@rstest/core';
export default defineConfig({
  onConsoleLog: () => false,
});
```
