@ued2345/laserbeak
Advanced tools
Comparing version 0.20.0-alpha.3 to 0.20.0-beta.1
{ | ||
"name": "@ued2345/laserbeak", | ||
"version": "0.20.0-alpha.3", | ||
"version": "0.20.0-beta.1", | ||
"description": "JS SDK for logging systems", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -11,2 +11,3 @@ import { exportGlobal } from './plugin/export-global' | ||
debug = false, | ||
isTesting = false, | ||
appName, | ||
@@ -16,3 +17,4 @@ appVersion, | ||
}) { | ||
appConfig.debug = debug | ||
appConfig.debug = !!debug | ||
appConfig.isTesting = !!isTesting | ||
if (!appName) { | ||
@@ -22,6 +24,7 @@ _log('[Logger] [Init] failed: `appName` is missing!') | ||
} | ||
if (!(appVersion || appVersion === 0)) { | ||
if (!appVersion && appVersion !== 0) { | ||
_log('[Logger] [Init] failed: `appVersion` is missing!') | ||
return | ||
} | ||
// TODO 规格化项目名:全小写、头尾空格 trim、内部空格转下划线 | ||
appConfig.appName = String(appName).toLowerCase() | ||
@@ -28,0 +31,0 @@ appConfig.appVersion = appVersion |
@@ -9,3 +9,3 @@ import { appConfig, log as _log, post } from '../util' | ||
function getMetadata(type) { | ||
function _getMetadata(type) { | ||
if (!type || validTypes.indexOf(type) === -1) type = 'event' | ||
@@ -17,3 +17,5 @@ | ||
prevUrl: document.referrer, | ||
appName: appConfig.appName, | ||
appVersion: appConfig.appVersion, | ||
// TODO | ||
// userId : appConfig.userId, | ||
@@ -31,2 +33,6 @@ } | ||
export function log(msg, type = 'event', data) { | ||
if (!appConfig._isSampled) { | ||
_log('[Logger] [Log] failed: current user is not sampled!') | ||
return | ||
} | ||
_log('[Logger] [Log] sending: ', msg, `(${ type })`, data) | ||
@@ -36,8 +42,9 @@ if (!msg) return | ||
// 前端项目上报日志时,项目名加前缀 `ued-`,以便在 Kibana 中与其它端的日志做区分、配置工作空间、配置对应的权限 | ||
// const project = 'ued-' + appConfig.appName | ||
const project = 'ued-demo' | ||
// 关于项目名: | ||
// 前端项目上报日志时,项目名加前缀 `ued-`,以便在 Kibana 中与其它端的日志做区分、配置工作空间、配置对应的权限。 | ||
// 在 meta.appName 中,保留了未加前缀的项目名,便于在 Kibana 中查询。 | ||
const project = 'ued-' + appConfig.appName | ||
const item = { | ||
meta: getMetadata(type), | ||
meta: _getMetadata(type), | ||
msg: String(msg), | ||
@@ -52,4 +59,2 @@ data, | ||
} | ||
// TODO 根据不同环境来决定是否上报时间戳:移动端上报,桌面端不上报(由服务端来定) | ||
// payload.timestamp = +(new Date()) | ||
@@ -60,4 +65,5 @@ return _report(payload) | ||
function _report(payload) { | ||
// 测试环境的 HTTP API | ||
const url = '//st0-middleware-logger.zt.2345.cn/api/v0/logging' | ||
const urlTesting = '//st0-middleware-logger.zt.2345.cn/api/v0/logging' | ||
const urlProduction = '//hades.2345.com/api/v0/logging' | ||
const url = appConfig.isTesting ? urlTesting : urlProduction | ||
@@ -70,7 +76,4 @@ const headers = { | ||
// TODO 具体暴露什么接口,需要再想一下 | ||
log.event = (name, data) => log(name, 'event', data) | ||
log.pv = (name, data) => log(name, 'pv', data) | ||
// log.pv = () => log('pv', 'pv') | ||
export const event = log.event | ||
export const pv = log.pv |
import { Sentry } from './sentry' | ||
import { log } from './log' | ||
@@ -7,3 +8,4 @@ // export as a Vue plugin | ||
Sentry, | ||
log, | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16091
481