Skip to content

Commit 2c2c068

Browse files
Add Sentry logging option
1 parent 4756c15 commit 2c2c068

4 files changed

Lines changed: 145 additions & 3 deletions

File tree

config-example.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"token": "The bot token",
3+
"sentryDSN": "Insert Public Sentry DNS here",
34
"prefix": "!",
45
"owner": "Your Discord-ID",
56
"ownertag": "Your Discord-Tag",

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const botconfig = require("./config.json");
33
const package = require("./package.json");
44
const Discord = require("discord.js");
55
const moment = require("moment");
6+
const Sentry = require('@sentry/node');
67
const tz = require("moment-timezone");
78
// noinspection JSCheckFunctionSignatures
89
const client = new Discord.Client({autoReconnect:botconfig.autorestart});
@@ -26,7 +27,7 @@ client.on("guildDelete", guild => {
2627
console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
2728
});
2829

29-
client.on('error', console.error);
30+
Sentry.init({ dsn: botconfig.sentryDSN});
3031

3132

3233
// Command rules
@@ -576,10 +577,12 @@ client.on("message", async message => {
576577
client.on('uncaughtException', (err) => {
577578
const errorMsg = err.stack.replace(new RegExp(`${__dirname}/`, 'g'), './');
578579
console.error('Uncaught Exception: ', errorMsg);
580+
Sentry.captureException("Uncaught Exception:" + errorMsg);
579581
});
580582

581583
client.on('unhandledRejection', err => {
582584
console.error('Uncaught Promise Error: ', err);
585+
Sentry.captureException("Uncaught Promise Error:" + err);
583586
});
584587

585588
});

package-lock.json

Lines changed: 138 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ink",
3-
"version": "0.5.6c",
3+
"version": "0.6.1c",
44
"description": "My very first Discord-Bot developed in JavaScript",
55
"main": "index.js",
66
"scripts": {
@@ -10,6 +10,7 @@
1010
"author": "Jan Klotz",
1111
"license": "MIT",
1212
"dependencies": {
13+
"@sentry/node": "^4.6.5",
1314
"colors": "^1.1.2",
1415
"discord.js": "^11.4.2",
1516
"moment": "^2.22.2",

0 commit comments

Comments
 (0)