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

pino-slack-webhook

v1.2.1

Published

🌲 Send message to Slack via webhook

Downloads

372

Readme

pino-slack-webhook

🌲 Send message to Slack via webhook

Installation

npm i pino-slack-webhook

Usage

$ pino-slack-webhook --help
pino-slack-webhook [options]

Sending
  -m, --method
             [string] [choices: "POST", "PUT", "PATCH", "GET"] [default: "POST"]
      --url      url to send logs to                         [string] [required]
  -t, --timeout  timeout (in ms) to send logs in bucket that are not filled
                                                        [number] [default: 5000]

Basic Auth
  -u, --username  basic auth username                                   [string]
  -p, --password  basic auth password                                   [string]

Retry
  -r, --retries   number of retries to do if failure       [number] [default: 5]
  -i, --interval  interval (in ms) to retry sending if failure
                                                        [number] [default: 1000]

Slack
      --unfurlLinks  Enables or disables link unfurling
                                                      [boolean] [default: false]
      --unfurlMedia  Enables or disables media unfurling
                                                      [boolean] [default: false]
  -m, --mrkdwn       Enables or disables mrkdwn formatting
                                                       [string] [default: false]

Options:
      --help     Show help                                             [boolean]
      --version  Show version number                                   [boolean]
  -l, --log      log to console as well               [boolean] [default: false]
      --silent   silence pino-slack-webhook logs for failures and retries
                                                      [boolean] [default: false]
  -c, --config   path to json config                                    [string]

Environment Variables

All options can be defined in the environment and are prefixed with PINO_SLACK_WEBHOOK_. All camel-cased options are parsed with delimiters of _.

e.g. The option unfurlLinks as an env var would be PINO_SLACK_WEBHOOK_UNFURL_LINKS.

URL

Example

node . | pino-slack-webhook --url=https://hooks.slack.com/services/xxx/xxx/xxx

Body Type

  • ndjson - New-line delimited JSON. See ndjson

  • json - Standard JSON sending of data. Logs are sent in the format of

    {
      "logs": [...logs]
    }

Auth

Currently only basic auth is implemented for the CLI usage. For header usage, you can see the API usage.

API

You can also use this module as a pino destination.

This will use the same batching function like the CLI usage. If the batch length is not reached within a certain time (timeout), it will auto "flush".

createWriteStream

The options passed to this follow the same values as the CLI defined above.

| Property | Type | Required/Default | | ----------- | ----------------------- | ---------------- | | url | string | REQUIRED | | log | boolean | false | | silent | boolean | false | | method | string | "POST" | | username | string | | | password | string | | | headers | Record<string,string> | | | retries | number | 5 | | interval | number | 1000 | | timeout | number | 5000 | | unfurlLinks | boolean | false | | unfurlMedia | boolean | false | | mrkdwn | boolean | false | | config | string | |

import { createWriteStream } from 'pino-slack-webhook';

const stream = createWriteStream({
  url: 'https://hooks.slack.com/services/xxx/xxx/xxx',
});

const logger = pino(
  {
    level: 'info',
  },
  stream,
);

logger.info('test log!');