Gathering detailed insights and metrics for winston-slack-webhook-transport-ts
Gathering detailed insights and metrics for winston-slack-webhook-transport-ts
Gathering detailed insights and metrics for winston-slack-webhook-transport-ts
Gathering detailed insights and metrics for winston-slack-webhook-transport-ts
A Slack transport for Winston 3 that logs to a channel via webhooks. Without emit, With enabling inject Proxy Agent
npm install winston-slack-webhook-transport-ts
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1 Stars
71 Commits
1 Watching
3 Branches
1 Contributors
Updated on 01 Feb 2024
TypeScript (88.75%)
JavaScript (11.25%)
Cumulative downloads
Total Downloads
Last day
0%
2
Compared to previous day
Last week
-96.1%
4
Compared to previous week
Last month
55.3%
278
Compared to previous month
Last year
-80.3%
1,592
Compared to previous year
2
This repository is forked from https://github.com/TheAppleFreak/winston-slack-webhook-transport
npm install winston winston-slack-webhook-transport-ts
1import * as winston from 'winston'; 2import httpsProxyAgent from 'https-proxy-agent'; 3import { 4 SlackTransport, 5 TransformableInfo, 6} from 'winston-slack-webhook-transport-ts'; 7 8const logger = winston.createLogger({ 9 level: "info", 10 transports: [ 11 new SlackTransport({ 12 level: 'error', 13 webhookUrl: "slack webhook url", 14 agent: httpsProxyAgent("sample agent url"), 15 formatter: (data: TransformableInfo) => { 16 return { 17 blocks: [ 18 { 19 type: 'section', 20 text: { 21 type: 'mrkdwn', 22 text: 23 '```' + 24 `[${NODE_ENV.toUpperCase()}][${data.level.toUpperCase()}] ${ 25 data.message 26 }` + 27 '```', 28 }, 29 }, 30 ], 31 }; 32 }, 33 }), 34 ] 35}); 36 37logger.info("This should now appear on Slack");
webhookUrl
REQUIRED - Slack incoming webhook
URL. Follow steps 1 through 3 at this link to create a new webhook if you don't already have one.formatter
- Custom function to format messages with. This function accepts the info
object (see Winston documentation)
and must return an object with at least one of the following three keys: text
(string), attachments
(array
of attachment objects), blocks
(array
of layout block objects). These will be used to
structure the format of the logged Slack message. By default, messages will use the format of [level]: [message]
with no attachments or layout blocks. A value of false
can also be returned to prevent a message from being sent to
Slack.level
- Level to log. Global settings will apply if left undefined.unfurlLinks
- Enables or
disables link unfurling. (
Default: false
)unfurlMedia
- Enables or
disables media unfurling. (
Default: false
)mrkdwn
- Enables or disables mrkdwn
formatting
within attachments or layout blocks (Default: false
)proxy
- Allows specifying a proxy server
that gets passed directly down to Axios (Default: undefined
)channel
- Overrides the webhook's default channel. This should be a channel ID. (Default: undefined
)username
- Overrides the webhook's default username. (Default: undefined
)iconEmoji
- An emoji code string to use in place of the
default icon. (Interchangeable with iconUrl
) (Default: undefined
)iconUrl
- An icon image URL string to use in place of the default icon. Interchangeable with iconEmoji
. (
Default: undefined
)agent
- An HttpAgent Instance. If you use httpsProxyAgent withimport httpsProxyAgent from 'https-proxy-agent'
, It will automatically enable proxy setting;winston-slack-webhook-transport-ts
supports the ability to format messages using Slack's message layout features. To
do this, supply a custom formatter function that returns
the requisite object structure to create the desired layout. You
can use the Slack Block Kit Builder to quickly and easily prototype advanced
layouts using Block Kit.
If for some reason you don't want to send a message to Slack, you can also return false
to prevent the log message
from being sent.
Formatters can also override the channel the message is posted to, username, and icon by defining the
properties channel
, username
, iconEmoji
, or iconUrl
in the same object structure. These will override any
options set in the transport constructor.
Note that if you're using Block Kit using either the attachments
or blocks
keys, the text
parameter will function
as a fallback for surfaces that do not support Block Kit, such as push notifications. It is recommended to
include text
when possible in these cases.
1import * as winston from 'winston'; 2import httpsProxyAgent from 'https-proxy-agent'; 3import { 4 SlackTransport, 5 TransformableInfo, 6} from 'winston-slack-webhook-transport-ts'; 7 8const logger = winston.createLogger({ 9 level: "info", 10 transports: [ 11 new SlackTransport({ 12 webhookUrl: "https://hooks.slack.com/services/xxx/xxx/xxx", 13 formatter: info => { 14 return { 15 text: "This will function as a fallback for surfaces that don't support Block Kit, like IRC clients or mobile push notifications.", 16 attachments: [ 17 { 18 text: "Or don't pass anything. That's fine too" 19 } 20 ], 21 blocks: [ 22 { 23 type: "section", 24 text: { 25 type: "plain_text", 26 text: "You can pass more info to the formatter by supplying additional parameters in the logger call" 27 } 28 } 29 ] 30 } 31 } 32 }) 33 ] 34}); 35 36logger.info("Definitely try playing around with this.");
No vulnerabilities found.
No security vulnerabilities found.