Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: log info and errors using the @slack/logger package #84

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app-oauth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { App, LogLevel } = require('@slack/bolt');
const { App } = require('@slack/bolt');
const { ConsoleLogger, LogLevel } = require('@slack/logger');
const { config } = require('dotenv');
const { registerListeners } = require('./listeners');

Expand Down Expand Up @@ -61,10 +62,11 @@ registerListeners(app);

/** Start Bolt App */
(async () => {
const logger = new ConsoleLogger();
Copy link
Member

@seratch seratch Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is at least better than now, but we may want to expose app.logger and use it here. With that, developers can control the logging level consistently

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩 I think that'd be most ideal! I agree that setting these levels in separate place isn't the best experience at the moment...

I'm also realizing this logger should be set to debug to match the app anyways!

try {
await app.start(process.env.PORT || 3000);
console.log('⚡️ Bolt app is running! ⚡️');
logger.info('⚡️ Bolt app is running!');
} catch (error) {
console.error('Unable to start App', error);
logger.error('Failed to start the App', error);
}
})();
8 changes: 5 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { App, LogLevel } = require('@slack/bolt');
const { App } = require('@slack/bolt');
const { ConsoleLogger, LogLevel } = require('@slack/logger');
const { config } = require('dotenv');
const { registerListeners } = require('./listeners');

Expand All @@ -17,10 +18,11 @@ registerListeners(app);

/** Start the Bolt App */
(async () => {
const logger = new ConsoleLogger();
try {
await app.start();
console.log('⚡️ Bolt app is running!');
logger.info('⚡️ Bolt app is running!');
} catch (error) {
console.error('Failed to start the app', error);
logger.error('Failed to start the app', error);
}
})();
4 changes: 2 additions & 2 deletions listeners/actions/sample-action.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const sampleActionCallback = async ({ ack, client, body }) => {
const sampleActionCallback = async ({ ack, client, body, logger }) => {
try {
await ack();
await client.views.update({
Expand Down Expand Up @@ -58,7 +58,7 @@ const sampleActionCallback = async ({ ack, client, body }) => {
},
});
} catch (error) {
console.error(error);
logger.error(error);
}
};

Expand Down
4 changes: 2 additions & 2 deletions listeners/commands/sample-command.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const sampleCommandCallback = async ({ ack, respond }) => {
const sampleCommandCallback = async ({ ack, respond, logger }) => {
try {
await ack();
await respond('Responding to the sample command!');
} catch (error) {
console.error(error);
logger.error(error);
}
};

Expand Down
4 changes: 2 additions & 2 deletions listeners/events/app-home-opened.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const appHomeOpenedCallback = async ({ client, event }) => {
const appHomeOpenedCallback = async ({ client, event, logger }) => {
// Ignore the `app_home_opened` event for anything but the Home tab
if (event.tab !== 'home') return;

Expand Down Expand Up @@ -26,7 +26,7 @@ const appHomeOpenedCallback = async ({ client, event }) => {
},
});
} catch (error) {
console.error(error);
logger.error(error);
}
};

Expand Down
4 changes: 2 additions & 2 deletions listeners/messages/sample-message.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const sampleMessageCallback = async ({ context, say }) => {
const sampleMessageCallback = async ({ context, say, logger }) => {
try {
const greeting = context.matches[0];
await say(`${greeting}, how are you?`);
} catch (error) {
console.error(error);
logger.error(error);
}
};

Expand Down
4 changes: 2 additions & 2 deletions listeners/shortcuts/sample-shortcut.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const sampleShortcutCallback = async ({ shortcut, ack, client }) => {
const sampleShortcutCallback = async ({ shortcut, ack, client, logger }) => {
try {
const { trigger_id } = shortcut;

Expand Down Expand Up @@ -62,7 +62,7 @@ const sampleShortcutCallback = async ({ shortcut, ack, client }) => {
},
});
} catch (error) {
console.error(error);
logger.error(error);
}
};

Expand Down
4 changes: 2 additions & 2 deletions listeners/views/sample-view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const sampleViewCallback = async ({ ack, view, body, client }) => {
const sampleViewCallback = async ({ ack, view, body, client, logger }) => {
await ack();

try {
Expand All @@ -11,7 +11,7 @@ const sampleViewCallback = async ({ ack, view, body, client }) => {
text: `<@${body.user.id}> submitted the following :sparkles: hopes and dreams :sparkles:: \n\n ${sampleInputValue}`,
});
} catch (error) {
console.error(error);
logger.error(error);
}
};

Expand Down
113 changes: 81 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"dependencies": {
"@slack/bolt": "^3.19.0",
"@slack/logger": "^4.0.0",
"dotenv": "~16.4.5"
},
"devDependencies": {
Expand Down