# @dreamit/otel-json-logger 中文文档

规范地址：https://npmcn.com/package/%40dreamit/otel-json-logger/

版本：3\.0\.3
npm 元数据更新时间：2025-07-10T14:33:15.777Z
中文译文更新时间：2026-11-13T05:04:50.176Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40dreamit/otel-json-logger
原文对照：https://npmcn.com/package/%40dreamit/otel-json-logger/?lang=original
项目主页：https://github.com/dreamit-de/otel-json-logger#readme
源码仓库：https://github.com/dreamit-de/otel-json-logger

弃用说明：@dreamit/otel-json-logger is deprecated and will no longer be maintained\. Use at your own risk\!

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

- 包体积（解压后）：62.7 kB，10 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- peer 依赖：@opentelemetry/api ^1\.6\.0
- 首次发布：2023-09-20T16:37:42.011Z
- 最新版本发布：2025-07-10T14:26:28.736Z
- 近 30 天下载量：2258（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：21（近 12 个月 0 个）

## 中文简介

JSON 诊断打开远程测量的日志

## 安装

```sh
npm install @dreamit/otel-json-logger
```

也可以使用：`pnpm add @dreamit/otel-json-logger`、`yarn add @dreamit/otel-json-logger`、`bun add @dreamit/otel-json-logger`

## README

# 奥特尔-杰森-洛格

JSON 诊断打开远程测量的日志

**折旧**:此图书馆将不再维持. 冒着自己的风险使用!

## 安装

```sh
npm install --save @dreamit/otel-json-logger
```

项目内提供类型脚本申报.

## 兼容性

**奥特尔-杰森-洛格** 与 [@ opletetmeterm/ api (打开的距离)](https://github.com/open-telemetry/opentelemetry-js) ^ 1. 6.0 版本.

## 特征

-   为 OpenTeleometry 提供 JSON 记录器 **对话框** 接口
-   用对象和阵列以及日志参数来字符串/检查信件,以避免破坏记录工具
-   为日志条目创建 ISODate 时间戳

## 使用量

创建一个 **杰森·迪亚格-洛克** 通过提供匹配对象 _日志器Name_ 财务报告和审定财务报表 _服务Name_。可以独立地使用记录器对 JSON 进行控制控制 全球 _对话框_。 。 。 .

```typescript
import { JsonDiagLogger } from '@dreamit/otel-json-logger'
import { diag, DiagLogLevel } from "@opentelemetry/api";

// Standalone
const logger = new JsonDiagLogger({
    loggerName: 'test-logger', // The loggerName printed in field "logger"
    serviceName: 'test-service', // The serviceName printed in field "serviceName"
    minLogLevel: 'INFO', // Optional: The minimum log level to use. Default: Does not check for min LogLevel.
    logFirstIncomingRequest: true, // Optional: If true, the first incoming request will be logged. Other messages on debug level will be log if minLogLevel is set to debug or higher. Default: false. Note: If you use diag.setLogger ensure that at least "DEBUG" is set, otherwise the message will be ignored.
    logLevelForAsyncAttributeError: 'INFO' // Optional: The log level to use for the message "Accessing resource attributes before async attributes settled". These errors might not be relevant enough to log them on error level.
    logLevelForRegisterGlobalMessages: 'INFO' // Optional: The log level to use for messages "... Registered a global ...". These are helpful to check if OTEL is running properly but are logged on debug level by default. Increase this log level to see these messages.
    logLevelForServiceRequestErrorMessages: 'INFO', // Optional: The log level to use for error message "Service request". These contain request information that might not be logged on error level.
    logLevelForTimeoutErrorMessages: 'INFO', // Optional: The log level to use for Timeout related messages. These might be of short nature and be downgraded or ignored.
    logLevelForVerbose: 'OFF' // Optional: Set LogLevel for verbose entries or ignore them
    truncateLimit: 200 // Optional:  The length of the message before the message gets truncated. Default: undefined/0 (off).
    truncatedText: '_TRC_' // Optional: The text to display if a message is truncated.
})
logger.debug('test', 1, {name: 'myname'})

// Add as global DiagLogger
diag.setLogger(logger, DiagLogLevel.ERROR)
```

## JsonDiagLogger 函数

### 一般职能

-   **创建日志 Entry**: 创建并返回类型日志条目 **日志条目** 提供了有关资料.
-   **负数**: 由所有人调用的中心功能 **对话框** 接口功能。 电话 **创建日志 Entry**,字符串结果和呼叫 **控制台.log ()**。 。 。 .
-   **格式**: 格式化信件。 如果信件中包含一个对象或阵列,将其包裹在JSON.stringify中以避免这些被解释为JSON对象.
-   **设置选项**: 设置 **锁定选项** 用于伐木。 可以在构建器调用后调用设置新/ 其他选项 .
-   **包含超时**:检查信件是否包含"4 DEADLINE EXED"或"14 UNAVAILALA"等超时信息.
-   **正在请求日志**:检查这些参数是否属于来函请求信件的一部分,即第一个参数包含"来函请求"的文本
-   **是等效或更高的明洛格级**:检查日志级别是否等于或高于最小日志级别.
-   **包含 Async 属性错误**: 检查信件中是否包含像"在Async属性确定前访问资源属性"这样的async属性错误.

### DiagLogger 接口功能

-   **调试**: 记录调试消息
-   **错误**: 记录错误消息
-   **资讯**: 记录信息消息
-   **动词**: 记录动词消息
-   **警告( e)**: 记录警告消息

### 日志级值

-   **吉布提**
-   **错误**
-   **信息通报**
-   **关闭** : 不要登录这些条目 !
-   **韦尔布斯**
-   **战争**

## 更改日志

### ưμ㼯a

_日志级别_ 已经从 enum 类型改为字符串类型.

## 联系人

如果你有问题,请访问我们 [问题页](https://github.com/dreamit-de/otel-json-logger/issues) 如果还没有适合你议题的问题,就打开一个新问题.

## 许可证

奥特尔 -杰森 -洛格下方 [麻省理工学院](https://npmcn.com/package/%40dreamit/otel-json-logger/LICENSE)。 。 。 .

## 常见问题

### @dreamit/otel-json-logger 是什么？

JSON 诊断打开远程测量的日志注意：该包已被作者标记为弃用——@dreamit/otel-json-logger is deprecated and will no longer be maintained\. Use at your own risk\!

### 如何安装 @dreamit/otel-json-logger？

在项目目录运行 npm install @dreamit/otel-json-logger，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@opentelemetry/api（^1\.6\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @dreamit/otel-json-logger 支持 TypeScript 吗？

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

### @dreamit/otel-json-logger 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @dreamit/otel-json-logger 可以商用吗？

@dreamit/otel-json-logger 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @dreamit/otel-json-logger 的下载量有多少？

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

### @dreamit/otel-json-logger 还在维护吗？

最新版本 3\.0\.3 发布于 2025/07/10（1\.3 年前）；至今共发布 21 个版本，其中过去 12 个月发布了 0 个；首次发布于 2023/09/21。作者已将其标记为弃用，新项目建议寻找替代方案。

