@evo/gotcha-log

中文文档
1.6.0发布于 2026/05/28ISCESM + CJS零依赖近 30 天下载 4822

锁定 来了。将使用 Global Gotcha 配置(如果 Gotcha 客户端在页面中已经存在,则比 窗口 将会是 真实 ) (中文(简体) ). 或者,如果在页面上没有卡, 它不会工作,直到你设置

中文使用文档
文档目录9 节
  1. 获取日志
  2. 安装
  3. API 密码
  4. 使用全局化的 Gotcha 客户端
  5. 用作独立记录器
  6. 额外日志
  7. txid 时
  8. @evo/gotcha-log/dist/量子
  9. 用法 :

获取日志

锁定 来了。 。 。 . 将使用 Global gotcha 配置( 如果 Gotcha 客户端已经在页面中存在, 而不是 窗口 将会是 真实 ) (中文(简体) ). 或者,如果在页面上没有卡, 它不会工作 直到你设置配置 initGotchaLogger 函数.

安装

npm install --save -E @evo/gotcha-log

API 密码

获得cha.log(msg,额外);

获得cha.error(msg,额外);

使用全局化的 Gotcha 客户端

import * as gotcha from '@evo/gotcha-log';
// or import { log } from '@evo/gotcha-log';

gotcha.log('test msg')
// or log('test msg')
gotcha.error('error msg')

用作独立记录器

import * as gotcha from '@evo/gotcha-log';

gotcha.initGotchaLogger(<GOTCHA_SITE>, <GOTCHA_HOST>, <TXID>)

gotcha.log('test');
gotcha.error('test');

请参看GOTCHA STE,GOTCHA HOST的细节 这里

生成的信息示例:

{
    "message":"test msg",
    "filename":"default",
    "screenWidth":1855,
    "screenHeight":1056,
    "userLanguage":"US",
    "currentUrl":"http://localhost:8000/",
    "site":"evodoc-dev",
    "type":"log"
}

额外日志

const extra = { user: { name: 'test', age: 1 } };
gotcha.log('test msg', extra);

将日志 :

{
    message: "test msg",
    ctx: { user_name_str: "test", user_age_int: 1 },
    //...
}

额外将按描述平整 这里

txid 时

默认情况下, gardecha 日志将从 Global gardecha 配置中应用 txid . 但你也可以说明 txid 附加参数中的每个日志 :

gotcha.log('test msg', { txid: '<some id>' });

@evo/gotcha-log/dist/量子

需要将事件度量衡的数值数据从前端转移到后端,以便在"普罗米修斯"中保存. 为此目的,创建了计量标准的子模块.

模块的设计受到软件包的启发 舞会客户

所有度量衡都使用上传到后端 窗口。 send Beacon ()。如果浏览器不支持此 API,则将返回到 XMLHttpRequest()

注:

在您的工程中添加参数之前, 您必须添加您的工程配置到 获取服务器

用法 :

常见用法 :

// at start of your application, initialize metrics module
import {initGotchaMetrics, metric} from '@evo/gotcha-log/dist/metrics';

initGotchaMetrics({
    project: <project-id>, // do not forget, to add your project to gotcha-server config
    host: <gotcha-backend-host>
});

// create metric: metric(<name>, [<value>], [<labels>])
metric(
    'pageview', // metric name
     1, // value
    {page:'koshyk'} // labels
)

您也可以手动创建参数实例 :

import { Counter } from '@evo/gotcha-log/dist/metrics';

const reduxActionsErrorsCounter=new Counter({
    name: 'redux-errors'
});
reduxActionsErrorsCounter.inc(123, {action: 'createOrder', version: '1.2.3'})

// or

const incCounter=reduxActionsErrorsCounter.getStandaloneInc( {action: 'createOrder', version: '1.2.3'})
incCounter(3) // which is equivalent to reduxActionsErrorsCounter.inc(3, {action: 'createOrder', version: '1.2.3'})

所有度量衡都会自动上传到后端每5s. 您可以通过拨打 :

import { stopUploadByInterval } from '@evo/gotcha-log/dist/metrics';
stopUploadByInterval()

并恢复它,打电话:

import { startUploadByInterval } from '@evo/gotcha-log/dist/metrics';
startUploadByInterval()

注:

startUploadByInterval 财务报告和审定财务报表 stopUploadByInterval 也添加 beforeonload 事件听众, 在用户离开当前页面前将上传到后端的参数

立即向后端发送参数 :

import { immediatelyUploadMetrics } from '@evo/gotcha-log/dist/metrics';
immediatelyUploadMetrics()

版本与发布记录

@evo/gotcha-log 共发布 20 个版本,首次发布于 2017/01/25;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.6.0latest2026/05/285 个月前
1.5.12021/04/285 年前
1.5.02021/04/285 年前
1.4.02019/04/257 年前
1.3.12018/01/228 年前
1.3.02017/11/089 年前

关于 @evo/gotcha-log 的常见问题

@evo/gotcha-log 是什么?

锁定 来了。将使用 Global Gotcha 配置(如果 Gotcha 客户端在页面中已经存在,则比 窗口 将会是 真实 ) (中文(简体) ). 或者,如果在页面上没有卡, 它不会工作,直到你设置

如何安装 @evo/gotcha-log?

在项目目录运行 npm install @evo/gotcha-log,或使用 pnpm add / yarn add / bun add。

@evo/gotcha-log 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/evo__gotcha-log 是否存在。

@evo/gotcha-log 支持 ESM 还是 CommonJS?

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

@evo/gotcha-log 可以商用吗?

@evo/gotcha-log 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@evo/gotcha-log 的下载量有多少?

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

@evo/gotcha-log 还在维护吗?

最新版本 1.6.0 发布于 2026/05/28(5 个月前);至今共发布 20 个版本,其中过去 12 个月发布了 1 个;首次发布于 2017/01/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。