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 🙏

© 2026 – Pkg Stats / Ryan Hefner

easemob-uniapp-logger-plugin

v1.5.0

Published

A logger plugin for uniapp applications

Readme

easemob-uniapp-logger-plugin

一个适用于 uni-app 应用的高性能日志收集工具类库,支持日志本地存储和上传到自定义服务器。

特性

  • 📱 多平台支持:兼容 iOS、Android (App平台) 和 微信小程序
  • 📝 日志级别:支持 DEBUG、INFO、WARN、ERROR、FATAL 级别
  • 💾 文件存储:App平台使用 plus.io 文件系统,小程序使用本地文件系统
  • 🗜️ 日志压缩:支持将日志文件压缩为 zip (App平台)
  • ☁️ 上传灵活:支持自定义服务器上传
  • ⚙️ 延迟写入:批量写入机制,减少 IO 操作

安装

npm install easemob-uniapp-logger-plugin

或直接将 dist/easemob-uniapp-logger.esm.js 复制到你的项目的 js_sdk 目录下。

快速开始

基础用法

//实际SDK
import websdk from '../js_sdk/Easemob-chat'
import {
  logger
} from '../js_sdk/easemob-uniapp-logger.esm.js'

// 创建 SDK 实例
const EMClient = new websdk.connection({
  appKey: 'YOUR_APPKEY#YOUR_ORG',
  url:'wss://im-api-wechat.easemob.com/websocket',
  apiUrl:'https://a1.easemob.com'
})
console.log('>>>>>SDK version', EMClient.version)
logger.init({
  conn: EMClient
});

// 如需禁用控制台输出(避免 hbuilderx 等 IDE 控制台日志过多)
// logger.setConsoleOutput(false);

websdk.logger.onLog = (data) => {
  console.log('>>>>>SDK输出的日志', data)
  logger.handleSDKLog(data);
}

上传到自定义服务器

import { logger } from 'easemob-uniapp-logger-plugin';

logger.init({
  customUpload: {
    handler: async (logContent) => {
      const deviceInfo = uni.getSystemInfoSync();
      
      // 上传到你的服务器
      const res = await uni.request({
        url: 'https://your-server.com/api/logs/upload',
        method: 'POST',
        header: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer your-api-token'
        },
        data: {
          logs: logContent,
          deviceInfo: {
            brand: deviceInfo.brand,
            model: deviceInfo.model,
            system: deviceInfo.system,
            platform: deviceInfo.platform,
          },
          timestamp: Date.now(),
        }
      });
      
      if (res.statusCode !== 200) {
        throw new Error('上传失败: ' + res.statusCode);
      }
    }
  }
});

// 在合适的时机调用上传
await logger.upload();

完整示例

在 App.vue 中使用

<script>
import { logger } from 'easemob-uniapp-logger-plugin';
import { conn } from '@/utils/websdk'; // 你的 SDK 实例

export default {
  globalData: { logger },
  
  onLaunch() {
    // 初始化 logger(传入 conn 以使用环信上传功能)
    logger.init({ conn });
    
    // 桥接 SDK 日志
    websdk.logger.onLog = (data) => {
      logger.handleSDKLog(data);
    };
    
    logger.info('App launched');
  },
  
  onError(err) {
    logger.error('App error', err);
  }
}
</script>

反馈页面上传日志

<template>
  <view class="feedback-page">
    <textarea v-model="content" placeholder="请输入反馈内容" />
    <button @click="submitFeedback">提交反馈并上传日志</button>
  </view>
</template>

<script>
import { logger } from 'easemob-uniapp-logger-plugin';

export default {
  data() {
    return { content: '' };
  },
  methods: {
    async submitFeedback() {
      try {
        uni.showLoading({ title: '上传中...' });
        logger.info('用户反馈', { content: this.content });
        await logger.upload();
        uni.showToast({ title: '提交成功', icon: 'success' });
      } catch (err) {
        uni.showToast({ title: '上传失败', icon: 'none' });
      }
    }
  }
}
</script>

API 文档

初始化

logger.init(options?: LoggerOptions): void

LoggerOptions:

| 属性 | 类型 | 描述 | |------|------|------| | log | Partial<LoggerConfig> | 日志配置 | | customUpload | CustomUploadConfig | 自定义上传配置 |

LoggerConfig:

| 属性 | 类型 | 默认值 | 描述 | |------|------|--------|------| | expireDays | number | 7 | 日志文件过期天数 | | maxFileSize | number | 2097152 (2MB) | 单个文件最大大小 | | uploadTimeout | number | 30000 | 上传超时时间(ms) | | enableConsoleOutput | boolean | true | 是否输出到控制台 |

记录日志

logger.debug(message: string, data?: unknown): void
logger.info(message: string, data?: unknown): void
logger.warn(message: string, data?: unknown): void
logger.error(message: string, data?: unknown): void
logger.fatal(message: string, data?: unknown): void

处理 SDK 日志

logger.handleSDKLog(data: SDKLogData): void

// 使用示例
websdk.logger.onLog = (data) => {
  logger.handleSDKLog(data);
};

上传日志

// 基础上传(使用初始化配置)
await logger.upload(options?: CustomUploadConfig);

// 上传到指定 URL
await logger.uploadTo(url: string, headers?: Record<string, string>);

// 使用自定义 handler
await logger.uploadWithHandler(handler: CustomUploadHandler);

其他方法

// 读取日志内容
const logs = await logger.read();

// 获取日志文件路径
const path = logger.getFilePath();

// 清空日志
await logger.clear();

// 压缩日志(App平台)
const zipPath = await logger.compress();

// 设置日志级别
logger.setMinLevel('WARN');

// 设置是否输出到控制台(用于控制 hbuilderx 等 IDE 的控制台输出)
logger.setConsoleOutput(false);

// 获取当前控制台输出状态
const isEnabled = logger.getConsoleOutput();

// 销毁 logger
logger.destroy();

构建产物

dist/
├── index.js                          # ES Module(默认入口)
├── easemob-uniapp-logger.esm.js      # ES Module(推荐用于 uni-app)
├── easemob-uniapp-logger.js          # UMD(用于 script 标签)
└── index.d.ts                        # TypeScript 类型声明

使用 ES Module(推荐)

import { logger } from './js_sdk/easemob-uniapp-logger.esm.js';

平台支持

| 功能 | App (iOS/Android) | 微信小程序 | H5/其他 | |------|-------------------|------------|---------| | 文件存储 | ✅ plus.io | ✅ wx FileSystem | ❌ 内存存储 | | 日志压缩 | ✅ plus.zip | ❌ | ❌ | | 上传(Handler) | ✅ | ✅ | ✅ |


日志格式

[2026-03-11 14:07:28.123] [DEBUG] 调试信息 {"detail":"xxx"}
[2026-03-11 14:07:28.456] [INFO] 用户登录成功 {"user":"alice"}
[2026-03-11 14:07:29.789] [ERROR] 请求失败 {"code":500}
[2026-03-11 14:07:30.012] [DEBUG] [SDK] Call fetchUserInfoById ["user1"]

License

MIT