Git Product home page Git Product logo

electron-reporter's Introduction

Electron Reporter

Electron && NW 日志上报模块

features

  • 根据上报类型分隔日志文件
  • 自动根据日期和文件大小分割日志文件
  • 排队上报到远程服务器, 失败自动重试, 保留所有原始日志
  • 自动把最近N天的日志文件打成加密压缩包并上传
  • 自动清理久远的历史日志

usage

npm install electron-reporter

  import Reporter from 'electron-reporter'
  let logger = new Reporter({
    // 上报server地址 必须
    url: 'xxx',
    // 日志文件上传地址
    uploadUrl: '',
    // 设备名字
    deviceName: '',
    // 客户端版本号
    version: '',
    // log文件存储目录 必须
    dir: process.cwd(),
    // 默认上报级别 默认是 3
    level: 3, // DEBUG: 1, INFO: 2, WARN: 3, ERROR: 4
    // 不同级别类型日志是否完全保存在本地, 默认全部保存在本地level级别为0
    // 一旦通过构造函数设置后, 便不可变更, 变更后也是无效的
    localLogLevel: 0,
    // 控制台log打印级别, 同上
    consoleLogLevel: 0,
    // 定时上报时间间隔 默认5分钟
    interval: 5 * 1000 * 60,
    // 一次上报日志数量允许的最大值, 默认 500
    maxCount: 500,
    // 日志文件命名的前缀 默认为空
    filenamePrefix: '',
    // 上报时需要ping的域名集合, 默认为空
    hosts: [],
    // 本地历史记录保持时间, 默认清除7天前的
    historyKeepDays: 7,
    // 临时文件保持时间, 默认清除3天前的
    tempKeepDays: 3,
    // 加密配置
    encryptOptions: {
      key: '',
      iv: '',
      clearEncoding: 'utf8',
      algorithm: 'aes-128-cbc'
    }
  })

  let params = {
     ad: 'tom',
     xx: 'xx',
     ...
  }

  logger.debug('Got cheese.', params);
  logger.info('Cheese is Gouda.', params);
  logger.warn('Cheese is quite smelly.', params);
  logger.error('Cheese is too ripe!', params);

setTimeout(() => {
  // 重设配置选项
  logger.configure({
    level: 0
  })
  // 强制立即上报
  logger.forceProcess()
}, 6000)

electron-reporter's People

Contributors

jarvanxing avatar xingyuzhe avatar

Forkers

xxcanghai

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.