Skip to content

Commit

Permalink
Add verbose option
Browse files Browse the repository at this point in the history
  • Loading branch information
youngkiu committed Jun 10, 2023
1 parent f5164a3 commit 5fd6add
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@youngkiu/pino-slack-webhook",
"version": "0.1.0",
"version": "0.1.1",
"description": "pino-slack-webhook is a Pino v7+ compatible transport to forward log events to Slack from a dedicated worker",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,33 @@ export default async function (opts: {
channel: string;
username?: string;
emoji?: string;
verbose?: boolean;
}) {
const {
webhookUrl,
channel,
username = 'webhookbot',
emoji = ':ghost:',
verbose = false,
} = opts;

if (!webhookUrl || !channel) {
throw new Error('The required options(webhookUrl, channel) are missing');
}

return build(async (source) => {
for await (const { msg } of source) {
for await (const obj of source) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { time, level, msg, err, error, stack, ...props } = obj;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { message: errMessage, stack: errStack, ...errorProps} = err || error || {};

await sendNotiToSlack({
url: webhookUrl,
channel,
username,
emoji,
text: msg,
text: verbose ? JSON.stringify(obj) : msg,
});
}
});
Expand Down
1 change: 1 addition & 0 deletions test/test-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const transport = pino.transport({
channel: '#error-noti',
username: 'testuser',
iconEmoji: 'testemoji',
verbose: true,
},
},
{
Expand Down

0 comments on commit 5fd6add

Please sign in to comment.