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

dingtalk-robot-transport

v0.1.3

Published

winston 的 transport,用于向钉钉机器人发送消息

Downloads

2

Readme

dingtalk-robot-transport

依赖

winston 2.x(目前不支持3.x版本)

钉钉机器人的token,如何生成钉钉机器人可以参考钉钉自定义机器人文档

可选参数

| 参数 |类型| 用途 | 默认值 | 必须 | 备注 | | :-----------: |:-:| :----------------------------------------------------------: | :----------------------------------------------------------: | :--: | :-----------: | | level |String| 指定日志输出级别 | - | 是 | | | token |String 或String[]| 指定日志推送的目标机器人 | - | 是 | 当token是个列表时并不是批量发送给每个token,而是用于拓展 | | title |[String]| | 日志通知 | 否 | | | appName |[String]| 应用的名称 | 读取项目根目录package.json,获取name属性,如果没有获取到会是unknown | 否 | | | hostname |[String]| 产生日志的服务器名 | 默认通过require('os').hostname()获取 | 否 | | | robotHookHost |[String]| 钉钉机器人推送的host | https://oapi.dingtalk.com | 否 | | | timestamp |[Function]| 格式化日志产生的时间戳 | moment的YYYY-MM-DD HH:mm:ss,SSS | 否 | | | formatter |[Function]| 自定义钉钉推送的消息格式 | format.simple | 否 | | | retries |[Number]| 钉钉消息推送失败之后重试次数,用户可以通过设置0来关闭重试功能 | 3 | 否 | 每次重试时,都会保证和上一次使用不同的token |

详细说明

  • timestamp(): String

    内置的timestamp是不接受任何参数的

  • formatter(info: Object): Object

函数参数是一个对象,有以下属性

| 参数 | 类型 | 备注 | | :--------: | :------: | :----------------------------------------------------------: | | msg | String | 日志的消息部分 | | meta | Object | 日志的meta部分 | | level | String | 日志的级别(过滤后的,例如:实例化的时候定义了level:info,这里的level只可能是info及其以上) | | title | String | 钉钉消息推送时的title | | appName | String | 应用的名称 | | hostname | String | 产生日志的服务器名 | | stimestamp | Function | 获取格式化后时间的函数 |

示例

  • timestamp
const moment = require('moment');

function timestamp() {
    return new moment(new Date()).format('YYYY-MM-DD HH:mm:ss,SSS');
};
  • formatter

    此函数的返回值会直接用于发送钉钉消息推送,所以用户可以在这里自定义任何钉钉支持的消息格式

    • simple
    import { transport as DingTalkRobotTransport, format  } from 'dingtalk-robot-transport'
      
    const logger = new winston.Logger({
      transports: [
        new DingTalkRobotTransport({
          name: 'dingTalk',
          hostname: 'dingTalk-robot',
          level: 'info',
          token: 'token',
          formatter: format.simple,
          maxLine: 2
        })
      ]
    });
      
    logger.info('riderId[1] traceId[1a9b7b50-dc03-11e8-bebd-8d484495fcd0]', '查询某某接口失败: ', new Error('just an error.'))

    simple

    • 未来会支持更多的格式

使用

yarn add dingtalk-robot-transport

import { transport as DingTalkRobotTransport, format } from 'winston'

const logger = new winston.Logger({
  transports: [
    new DingTalkRobotTransport({
      name: 'dingTalk', // winston 本身的限制,这个是必须的
      hostname: 'dingTalk-robot', // 可选参数
      level: 'error',
			token: 'your robot token', // ['token1', 'token2'],启用多个token,降低频率(20条/分钟)限制的影响
      retries: 0, // 默认: 3,失败(包括频率限制导致的失败)会重试 3 次 ,多个 token 时每次重试会使用和上一次不同的token
      maxLine: 2
    })
  ]
});

logger.info('robot token')

ChangeLog

  • v1.0.0

计划

  • [ ] 添加频率控制功能。超过指定频率的错误在一段时间内不再推送