获取日志
锁定 来了。 。 。 .
将使用 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()