npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hd-lib/hd-sls-logger

v1.2.0-alpha.1

Published

haoduo js端sls日志服务sdk

Downloads

2

Readme

@hd/hd-sls-logger

好多兴趣班内部使用的 sls 日志服务 js 库。

兼容 普通h5, taro 小程序, mpass webview 容器 h5。

埋点文档见: https://haoduo.yuque.com/cpwd/yhdwd/yaogkl

功能

所有端统一写法。 在 mpass webview 内直接调用了 native 方法,使用官方 sdk。 在 普通h5, taro 小程序内实现异常捕获,重试机制。

用法

1.安装依赖包

yarn add  @hd/hd-sls-logger

2.import在您的应用程序模块。

h5:


import HdSlsLogger from '@hd/hd-sls-logger'

taro:

import HdSlsLogger from '@hd/hd-sls-logger'

4.配置参数并创建HdSlsLogger对象。(在单独文件里创建,使用时引用实例)

const opts = {
  host: '${host}', // 所在区域的host
  project: '${project}', // project名称
  logstore: '${logstore}', // logstore名称
  getUserInfo?, // 获取用户信息函数 返回对象需要有 userId 小程序用,h5不需要
  getUserCity?, // 获取城市函数 返回对象需要有 cityName cityId 小程序用,h5不需要
  errorFun?, // 错误回调函数,返回error和data 可以用这个回调接 sentry
}

// __logs__层除 data 和 time 外其他数据,大部分是项目参数
const logInfo = {
  __project__: "好多兴趣班小程序",
  __app_version__: "1.2.3",
  uid: "",
  channel: "",
  client: "",
  "app-version": "",
  "city-id": "",
  "city-name": "",
  "device-id": "",
  "device-model": "",
  traceId: "",
  "weex-version": "",
  "system-version": "",
}

const logger = new HdSlsLogger(opts, logInfo)
export default logger

5.上传日志。

普通上传:(先缓存再发送)

logger.send(
  eventName?: string, // topic
  params = {}, // 附参
  source: string = 'event_log', // 页面埋点 page_log, 行为埋点 event_log
  baseData?: {}, // 基础数据,会加到埋点数据最外层
)

立即上传:(失败再缓存)

logger.sendNow(
  eventName?: string, // topic
  params = {}, // 附参
  source: string = 'event_log', // 页面埋点 page_log, 行为埋点 event_log
  baseData?: {}, // 基础数据,会加到埋点数据最外层
)

发送spm日志

logger.sendSpm(
  spm?: string, // spm值
  params = {},// 附参
  source?: string = 'event_log', // 页面埋点 page_log, 行为埋点 event_log
  sendNowBoolean?:boolean, // 判断立即上传还是普通上传,默认普通上传,即先缓存再发送
  baseData = {} // 基础数据,会加到埋点数据最外层
)

其他方法

修改之前设置的logInfo:

logger.setLogInfo({
  __project__: "好多兴趣班小程序",
  __app_version__: "1.2.3",
  uid: "",
  channel: "",
  client: "",
  "app-version": "",
  "city-id": "",
  "city-name": "",
  "device-id": "",
  "device-model": "",
  traceId: "",
  "weex-version": "",
  "system-version": "",
})

更新日志

  • 1.1.0

    • 增加静态方法:HdSlsLogger.getTraceId
    • 增加静态方法:HdSlsLogger.saveTraceId(uuid: string)
  • 1.1.3

    • 修改上传日志的缓存策略,之前是所有日志存一个位置,改成了每条日志都存不一样的位置,减少json解析时间。
    • 新增立即发送方法 sendNow
    • 新增发送 spm 方法 sendSpm
  • 1.1.4

    • 去除 sentry,改成在宿主环境通过errorFun回调来发送sentry错误信息。此做法可以减少包体积,增加扩展性(比如以后用其他的错误收集框架)。