diff --git a/app-oauth.js b/app-oauth.js index 8567718..568edcd 100644 --- a/app-oauth.js +++ b/app-oauth.js @@ -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'); @@ -61,10 +62,12 @@ registerListeners(app); /** Start Bolt App */ (async () => { + const logger = new ConsoleLogger(); + logger.setLevel(LogLevel.DEBUG); 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); } })(); diff --git a/app.js b/app.js index d0ce44d..2d06c6f 100644 --- a/app.js +++ b/app.js @@ -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'); @@ -17,10 +18,12 @@ registerListeners(app); /** Start the Bolt App */ (async () => { + const logger = new ConsoleLogger(); + logger.setLevel(LogLevel.DEBUG); 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); } })(); diff --git a/listeners/actions/sample-action.js b/listeners/actions/sample-action.js index 796b7d3..65d73a4 100644 --- a/listeners/actions/sample-action.js +++ b/listeners/actions/sample-action.js @@ -1,4 +1,4 @@ -const sampleActionCallback = async ({ ack, client, body }) => { +const sampleActionCallback = async ({ ack, client, body, logger }) => { try { await ack(); await client.views.update({ @@ -58,7 +58,7 @@ const sampleActionCallback = async ({ ack, client, body }) => { }, }); } catch (error) { - console.error(error); + logger.error(error); } }; diff --git a/listeners/commands/sample-command.js b/listeners/commands/sample-command.js index 460545c..9ac402f 100644 --- a/listeners/commands/sample-command.js +++ b/listeners/commands/sample-command.js @@ -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); } }; diff --git a/listeners/events/app-home-opened.js b/listeners/events/app-home-opened.js index 8a9bb45..4721a14 100644 --- a/listeners/events/app-home-opened.js +++ b/listeners/events/app-home-opened.js @@ -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; @@ -26,7 +26,7 @@ const appHomeOpenedCallback = async ({ client, event }) => { }, }); } catch (error) { - console.error(error); + logger.error(error); } }; diff --git a/listeners/messages/sample-message.js b/listeners/messages/sample-message.js index c691348..7d8a8b2 100644 --- a/listeners/messages/sample-message.js +++ b/listeners/messages/sample-message.js @@ -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); } }; diff --git a/listeners/shortcuts/sample-shortcut.js b/listeners/shortcuts/sample-shortcut.js index 656c8f7..bbf2865 100644 --- a/listeners/shortcuts/sample-shortcut.js +++ b/listeners/shortcuts/sample-shortcut.js @@ -1,4 +1,4 @@ -const sampleShortcutCallback = async ({ shortcut, ack, client }) => { +const sampleShortcutCallback = async ({ shortcut, ack, client, logger }) => { try { const { trigger_id } = shortcut; @@ -62,7 +62,7 @@ const sampleShortcutCallback = async ({ shortcut, ack, client }) => { }, }); } catch (error) { - console.error(error); + logger.error(error); } }; diff --git a/listeners/views/sample-view.js b/listeners/views/sample-view.js index 9482cb7..a79ef59 100644 --- a/listeners/views/sample-view.js +++ b/listeners/views/sample-view.js @@ -1,4 +1,4 @@ -const sampleViewCallback = async ({ ack, view, body, client }) => { +const sampleViewCallback = async ({ ack, view, body, client, logger }) => { await ack(); try { @@ -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); } }; diff --git a/package-lock.json b/package-lock.json index d11932b..ce2b360 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { - "name": "bolt-js-template", + "name": "bolt-js-starter-template", "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "bolt-js-template", + "name": "bolt-js-starter-template", "version": "1.0.0", "license": "MIT", "dependencies": { "@slack/bolt": "^3.19.0", + "@slack/logger": "^4.0.0", "dotenv": "~16.4.5" }, "devDependencies": { @@ -223,33 +224,22 @@ "npm": ">=6.12.0" } }, - "node_modules/@slack/bolt/node_modules/@slack/logger": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-4.0.0.tgz", - "integrity": "sha512-Wz7QYfPAlG/DR+DfABddUZeNgoeY7d1J39OCR2jR+v7VBsB8ezulDK5szTnDDPDwLH5IWhLvXIHlCFZV7MSKgA==", - "dependencies": { - "@types/node": ">=18.0.0" - }, - "engines": { - "node": ">= 18", - "npm": ">= 8.6.0" - } - }, "node_modules/@slack/bolt/node_modules/path-to-regexp": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.1.tgz", "integrity": "sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==" }, "node_modules/@slack/logger": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-3.0.0.tgz", - "integrity": "sha512-DTuBFbqu4gGfajREEMrkq5jBhcnskinhr4+AnfJEk48zhVeEv3XnUKGIX98B74kxhYsIMfApGGySTn7V3b5yBA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-4.0.0.tgz", + "integrity": "sha512-Wz7QYfPAlG/DR+DfABddUZeNgoeY7d1J39OCR2jR+v7VBsB8ezulDK5szTnDDPDwLH5IWhLvXIHlCFZV7MSKgA==", + "license": "MIT", "dependencies": { - "@types/node": ">=12.0.0" + "@types/node": ">=18.0.0" }, "engines": { - "node": ">= 12.13.0", - "npm": ">= 6.12.0" + "node": ">= 18", + "npm": ">= 8.6.0" } }, "node_modules/@slack/oauth": { @@ -269,6 +259,19 @@ "npm": ">=6.12.0" } }, + "node_modules/@slack/oauth/node_modules/@slack/logger": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-3.0.0.tgz", + "integrity": "sha512-DTuBFbqu4gGfajREEMrkq5jBhcnskinhr4+AnfJEk48zhVeEv3XnUKGIX98B74kxhYsIMfApGGySTn7V3b5yBA==", + "license": "MIT", + "dependencies": { + "@types/node": ">=12.0.0" + }, + "engines": { + "node": ">= 12.13.0", + "npm": ">= 6.12.0" + } + }, "node_modules/@slack/socket-mode": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/@slack/socket-mode/-/socket-mode-1.3.3.tgz", @@ -290,6 +293,19 @@ "npm": ">=6.12.0" } }, + "node_modules/@slack/socket-mode/node_modules/@slack/logger": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-3.0.0.tgz", + "integrity": "sha512-DTuBFbqu4gGfajREEMrkq5jBhcnskinhr4+AnfJEk48zhVeEv3XnUKGIX98B74kxhYsIMfApGGySTn7V3b5yBA==", + "license": "MIT", + "dependencies": { + "@types/node": ">=12.0.0" + }, + "engines": { + "node": ">= 12.13.0", + "npm": ">= 6.12.0" + } + }, "node_modules/@slack/types": { "version": "2.11.0", "resolved": "https://registry.npmjs.org/@slack/types/-/types-2.11.0.tgz", @@ -321,6 +337,19 @@ "npm": ">= 6.12.0" } }, + "node_modules/@slack/web-api/node_modules/@slack/logger": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-3.0.0.tgz", + "integrity": "sha512-DTuBFbqu4gGfajREEMrkq5jBhcnskinhr4+AnfJEk48zhVeEv3XnUKGIX98B74kxhYsIMfApGGySTn7V3b5yBA==", + "license": "MIT", + "dependencies": { + "@types/node": ">=12.0.0" + }, + "engines": { + "node": ">= 12.13.0", + "npm": ">= 6.12.0" + } + }, "node_modules/@slack/web-api/node_modules/p-queue": { "version": "6.6.2", "resolved": "https://registry.npmjs.org/p-queue/-/p-queue-6.6.2.tgz", @@ -3706,14 +3735,6 @@ "tsscmp": "^1.0.6" }, "dependencies": { - "@slack/logger": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-4.0.0.tgz", - "integrity": "sha512-Wz7QYfPAlG/DR+DfABddUZeNgoeY7d1J39OCR2jR+v7VBsB8ezulDK5szTnDDPDwLH5IWhLvXIHlCFZV7MSKgA==", - "requires": { - "@types/node": ">=18.0.0" - } - }, "path-to-regexp": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.1.tgz", @@ -3722,11 +3743,11 @@ } }, "@slack/logger": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-3.0.0.tgz", - "integrity": "sha512-DTuBFbqu4gGfajREEMrkq5jBhcnskinhr4+AnfJEk48zhVeEv3XnUKGIX98B74kxhYsIMfApGGySTn7V3b5yBA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-4.0.0.tgz", + "integrity": "sha512-Wz7QYfPAlG/DR+DfABddUZeNgoeY7d1J39OCR2jR+v7VBsB8ezulDK5szTnDDPDwLH5IWhLvXIHlCFZV7MSKgA==", "requires": { - "@types/node": ">=12.0.0" + "@types/node": ">=18.0.0" } }, "@slack/oauth": { @@ -3740,6 +3761,16 @@ "@types/node": ">=12", "jsonwebtoken": "^9.0.0", "lodash.isstring": "^4.0.1" + }, + "dependencies": { + "@slack/logger": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-3.0.0.tgz", + "integrity": "sha512-DTuBFbqu4gGfajREEMrkq5jBhcnskinhr4+AnfJEk48zhVeEv3XnUKGIX98B74kxhYsIMfApGGySTn7V3b5yBA==", + "requires": { + "@types/node": ">=12.0.0" + } + } } }, "@slack/socket-mode": { @@ -3757,6 +3788,16 @@ "p-cancelable": "^1.1.0", "p-queue": "^2.4.2", "ws": "^7.5.3" + }, + "dependencies": { + "@slack/logger": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-3.0.0.tgz", + "integrity": "sha512-DTuBFbqu4gGfajREEMrkq5jBhcnskinhr4+AnfJEk48zhVeEv3XnUKGIX98B74kxhYsIMfApGGySTn7V3b5yBA==", + "requires": { + "@types/node": ">=12.0.0" + } + } } }, "@slack/types": { @@ -3782,6 +3823,14 @@ "p-retry": "^4.0.0" }, "dependencies": { + "@slack/logger": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@slack/logger/-/logger-3.0.0.tgz", + "integrity": "sha512-DTuBFbqu4gGfajREEMrkq5jBhcnskinhr4+AnfJEk48zhVeEv3XnUKGIX98B74kxhYsIMfApGGySTn7V3b5yBA==", + "requires": { + "@types/node": ">=12.0.0" + } + }, "p-queue": { "version": "6.6.2", "resolved": "https://registry.npmjs.org/p-queue/-/p-queue-6.6.2.tgz", diff --git a/package.json b/package.json index 83486f3..b3b8859 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ }, "dependencies": { "@slack/bolt": "^3.19.0", + "@slack/logger": "^4.0.0", "dotenv": "~16.4.5" }, "devDependencies": {