# @bifold/remote-logs 中文文档

规范地址：https://npmcn.com/package/%40bifold/remote-logs/

版本：3\.1\.4
npm 元数据更新时间：2026-11-04T16:48:43.508Z
中文译文更新时间：2026-11-08T01:44:55.563Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40bifold/remote-logs
原文对照：https://npmcn.com/package/%40bifold/remote-logs/?lang=original
项目主页：https://github.com/openwallet-foundation/bifold-wallet
源码仓库：https://github.com/openwallet-foundation/bifold-wallet

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：43 kB，13 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：7 个
- peer 依赖：axios ~1\.15\.0，react 19\.2\.3，buffer ~6\.0\.3，react-native 0\.86\.3，@credo-ts/core 0\.7\.0，react-native-logs ~5\.1\.0
- 首次发布：2025-04-14T21:28:58.578Z
- 最新版本发布：2026-11-04T16:48:43.123Z
- 近 30 天下载量：2016（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：92（近 12 个月 53 个）

## 中文简介

信条代理的远程记录

## 安装

```sh
npm install @bifold/remote-logs
```

也可以使用：`pnpm add @bifold/remote-logs`、`yarn add @bifold/remote-logs`、`bun add @bifold/remote-logs`

## README

# TL; DR 数据

这个 `@hyperledger/aries-remote-logs` 软件包提供了简单的发送方式 [信条](https://github.com/openwallet-foundation/credo-ts) (克里多)日志到远程 [罗基](https://grafana.com/docs/loki/latest/) 服务器.

## 使用量

此软件包允许将 Credo 日志的副本发送到远程的 Loki 服务器 。 这对于在日志不易访问的环境中调试问题有用,但需要日志来提供 [三级](https://en.wikipedia.org/wiki/Technical_support) 支助.

由于可核查的证书和数字身份的敏感性一般,日志不会自动发送. 相反,必须启用这一功能。 没错 **高度建议** 该特性在生产环境中默认被禁用,并且只有在最终用户需要时才启用,甚至会在短时间内自动被禁用.

### 考虑因素

当远程记录启用时 `RemoteLogger` 将自动生成会话ID。 此ID随后被设定为发送到远程服务器的所有日志上的标签 。 这允许通过会话ID过滤日志. 这在调试单个用户特有的问题时有用.

当终端用户启用远程日志时, 将会向他们展示会话ID 。 身份证应记录在案并提供给支助小组。 支援小组然后可以使用这个ID来识别正确的日志. 此会话ID也有助于最小化日志与终端用户的芯片连接.

![Remote Warning Screenshot](https://npmcn.com/package/%40bifold/remote-logs/doc/assets/warning-screenshot.jpeg)

用以下代码获取会话ID:

```typescript
// ...
const { agent } = useAgent()
const logger = agent?.config.logger as RemoteLogger

console.log(`Session ID: ${logger.sessionId}`)
```

### 配置

这个 `RemoteLogger` 配置了一组选项。 这些选项将传递给 `RemoteLogger` 课。 备选方案如下:

| 选项 | 类型 | 说明 |
| --- | --- | --- |
| `lokiUrl` | `string` | Loki服务器的完整 URL . |
| `lokiLabels` | `Record<string, string>` | 一组标签将应用于发送到Loki服务器的所有日志. |
| `autoDisableRemoteLoggingIntervalInMinutes` | `number` | 自动禁用远程日志前的等待分钟数 . |

下面的图像显示了典型的Grafana日志查询的外观. 查询由 `application` 财务报告和审定财务报表 `job` 标签。 这个 `sessionId` 标签用于过滤特定调试会话的日志.

![Grafana Screenshot](https://npmcn.com/package/%40bifold/remote-logs/doc/assets/grafana-screenshot.png)

### 示例使用

设置 `RemoteLogger` 把它传给克里多 `Agent` 如下所示:

```typescript
import { RemoteLogger, RemoteLoggerOptions } from '@hyperledger/aries-remote-logs'

// ...

const autoDisableRemoteLoggingIntervalInMinutes = 90 // important
const lokiUrl = 'https://logs.example.com:3100/loki/api/v1/push'
const logOptions: RemoteLoggerOptions = {
  lokiUrl,
  lokiLabels: {
    application: 'bifold-wallet',
    job: 'react-native-logs',
  },
  autoDisableRemoteLoggingIntervalInMinutes,
}

const logger = new RemoteLogger(logOptions)
logger.startEventListeners()

const credoConfigOpts = {
  config: {
    label: 'Bifold Wallet',
    walletConfig: {
      id: 'some-wallet-id',
      key: 'some-secret-key',
    },
    logger,
    mediatorPickupStrategy: MediatorPickupStrategy.Implicit,
    autoUpdateStorageOnStartup: true,
    autoAcceptConnections: true,
  },
  dependencies: agentDependencies,
  modules: getAgentModules({
    indyNetworks: ledgers,
    mediatorInvitationUrl: Config.MEDIATOR_URL,
  }),
}

const agent = new Agent(credoConfigOpts)

// ...
```

通过发送下列事件启用并禁用远程记录 :

```typescript
import { DeviceEventEmitter } from 'react-native'
import { RemoteLoggerEventTypes } from '@hyperledger/aries-remote-logs'

// ...

// enable remote logging, this will send the logs to the remote server
// and will automatically disable remote logging after the specified
// interval.
DeviceEventEmitter.emit(RemoteLoggerEventTypes.ENABLE_REMOTE_LOGGING, true)

// ...
```

### 包括一揽子计划

**地铁**

地铁无法处理"同心通". 因此,您需要指定 `@hyperledger/aries-remote-logs` 位置位于 `metro.config.js` 申请文件。 检查下面的例子, 或者查看这个 [完整实例](https://github.com/bcgov/bc-wallet-mobile/blob/main/app/metro.config.js) 更多信息.

```javascript
// ...
fs.realpathSync(path.join(__dirname, 'node_modules', '@hyperledger/aries-remote-logs')),
// ...
```

**雅伦**

亚伦挣扎要包括 `react-native` 本地文件系统对等依赖。 要修复, 请添加任何 `react-native` 此软件包的依赖性 `peerDependencies` 内 `package.json` 给自己的 `package.json`命令 `yarn add react-native-logs@^5.0.1` 这样做.

## 发展

这个包船带有一个可以用来运行当地Grafana Loki堆栈的多克编组文件. 要启动容器,运行以下命令:

```bash
docker compose up -d
```

Loki 服务器将在 `http://localhost:3100`。格拉法纳服务器将在 `http://localhost:3000`。Grafana 的默认用户名和密码是 `admin` 并指定密码,可以更改,在 `docker-compose.yaml` 文件 :

```yaml
environment:
  GF_SECURITY_ADMIN_PASSWORD: secret
```

一旦堆栈开始运行,您已经登录到Grafana,您可能需要从主登陆页上添加一个Loki数据源. 您需要设置的唯一值是 Loki 运行的 URL 。 根据堆放器,值是: `http://loki:3100`

## 常见问题

### @bifold/remote-logs 是什么？

信条代理的远程记录

### 如何安装 @bifold/remote-logs？

在项目目录运行 npm install @bifold/remote-logs，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：axios（~1\.15\.0）、react（19\.2\.3）、buffer（~6\.0\.3）、react-native（0\.86\.3）、@credo-ts/core（0\.7\.0）、react-native-logs（~5\.1\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @bifold/remote-logs 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @bifold/remote-logs 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @bifold/remote-logs 可以商用吗？

@bifold/remote-logs 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @bifold/remote-logs 的下载量有多少？

根据 npm 官方下载统计，@bifold/remote-logs 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,016 次，日均约 67 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @bifold/remote-logs 还在维护吗？

最新版本 3\.1\.4 发布于 2026/11/05（3 天前）；至今共发布 92 个版本，其中过去 12 个月发布了 53 个；首次发布于 2025/04/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

