Skip to content

Commit 852defa

Browse files
committed
Replaced console.log with sentry's logger
1 parent 0c4b43a commit 852defa

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

src/core/YoutubeClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { youtube } from "../config.json";
55
import type { DiscordClient } from "./DiscordClient";
66
import type { ServiceClient } from "./ServiceClient";
77
import type { TextChannel } from "discord.js";
8+
import { logger } from "@sentry/node-core";
89

910
/*
1011
Example Reference
@@ -79,7 +80,7 @@ export class YoutubeClient extends YouTubeNotifier implements baseClient {
7980
this.service = service;
8081
this.dClient = dClient;
8182
service.express.use(Path, this.listener());
82-
console.log(`Current PubSub URL: ${pubsuburl}`);
83+
logger.info(`Configured PubSub URL: ${pubsuburl}`);
8384

8485
// Register events
8586
new YoutubeEvents(this)

src/events/YoutubeEvents.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { NotifiedEvent, SubEvent, YoutubeClient } from "../core/YoutubeClie
22
import { baseEvent } from "../core/baseEvent";
33
import { youtube } from "../config.json";
44
import { sendLog } from "../utils/eventLogger";
5+
import { logger } from "@sentry/node-core";
56

67

78
export class YoutubeEvents extends baseEvent {
@@ -31,14 +32,16 @@ export class YoutubeEvents extends baseEvent {
3132
return;
3233

3334
await this.client.service.redis.set(`youtube:${data.video.id}`, "true", "EX", 43200);
34-
console.log(`Video (${data.video.id}) was notified with Publish: ${data.published} and Updated: ${data.updated}`);
35+
logger.info(`Published Youtube Video ID: ${data.video.id}`, {
36+
publishTime: data.published,
37+
updateTime: data.updated
38+
});
3539

3640
const rolePing = this.config.pingRoleID !== "0" ? `<@&${this.config.pingRoleID}>` : "";
3741
this.client.alertChannel?.send({ content: `${rolePing} New Video is out!! Check it out here: ${data.video.link}` });
3842
}
3943

4044
private async subscribe(data: SubEvent) {
41-
console.log("Youtube Notification Service: PubSubHubbub has been Subscribed...");
4245
await sendLog({
4346
type: "Info",
4447
message: "Youtube Notification Service: PubSubHubbub has been Subscribed..."
@@ -56,7 +59,6 @@ export class YoutubeEvents extends baseEvent {
5659
}
5760

5861
private async unsubscribe() {
59-
console.log("Youtube Notification Service: Even has been unsubscribed, resubscribing...");
6062
await sendLog({
6163
type: "Warning",
6264
message: "Youtube Notification Service: Even has been unsubscribed, resubscribing..."

src/events/redisEvents.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Worked on after logger is added...
22

3-
import { captureException } from "@sentry/node-core";
3+
import { captureException, logger } from "@sentry/node-core";
44
import { sendLog } from "../utils/eventLogger";
55
import type Redis from "ioredis";
66

@@ -40,7 +40,7 @@ export class RedisEvents {
4040
this.alreadyReconWarned = false;
4141
this.errCount = 0;
4242

43-
console.log("Redis Connected");
43+
logger.info("Redis Connected");
4444
sendLog({
4545
type: "Info",
4646
message: "Redis: Connection Established"
@@ -53,7 +53,7 @@ export class RedisEvents {
5353
if(this.alreadyReconWarned)
5454
return;
5555

56-
console.log("Redis reconnecting...");
56+
logger.debug("Redis reconnecting...");
5757
sendLog({
5858
type: "Warning",
5959
message: "Redis: Connection Issue, Reconnecting..."

src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DiscordClient } from "./core/DiscordClient";
2-
import { flush } from "@sentry/node-core";
2+
import { logger, close } from "@sentry/node-core";
33
import { sendLog } from "./utils/eventLogger";
44
import { TwitchClient } from "./core/TwitchClient";
55
import { YoutubeClient } from "./core/YoutubeClient";
@@ -25,7 +25,7 @@ const YoutubeCli = new YoutubeClient(svcClient, CoreClient);
2525
(async ()=>{
2626
await svcClient.start();
2727
await CoreClient.start(process.env["BOTTOKEN"]!);
28-
console.log("Bot started");
28+
logger.info("Bot started");
2929
await TwitchCli.start();
3030
CoreClient.setTwitchClient(TwitchCli);
3131
await YoutubeCli.start();
@@ -43,13 +43,12 @@ async function quitSignalHandler() {
4343
type: "Info",
4444
message: "Shutdown Initiated... View logs for shutdown completion."
4545
});
46-
console.log("Shutdown Initiated...");
4746

4847
// Perform cleanup
4948
await CoreClient.dispose();
5049
await TwitchCli.dispose();
5150
await TwitchCli.dispose();
52-
await flush(15000);
51+
await close(15000);
5352

5453
// Complete the shutdown
5554
console.log("Shutdown Complete!");

src/loader.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { Breadcrumb, ErrorEvent, EventHint, StackFrame } from "@sentry/node-core";
2+
import type { Log } from "@sentry/core";
23
import { relative } from "path";
34
import { DiscordAPIError, DiscordjsError } from "discord.js";
45
import { APIErrors } from "./utils/discordErrorCode";
56
import { Prisma } from "@prisma/client";
67
import { errors } from 'undici';
78
import {
8-
consoleLoggingIntegration,
99
extraErrorDataIntegration,
1010
rewriteFramesIntegration,
1111
SentryContextManager,
@@ -35,6 +35,7 @@ const cli = sentryInit({
3535

3636
beforeBreadcrumb,
3737
beforeSend,
38+
beforeSendLog,
3839
beforeSendTransaction: () => null,
3940

4041
ignoreErrors: [
@@ -50,9 +51,6 @@ const cli = sentryInit({
5051
],
5152

5253
integrations: [
53-
consoleLoggingIntegration({
54-
levels: ["error", "warn", "log"],
55-
}),
5654
extraErrorDataIntegration({
5755
depth: 5
5856
}),
@@ -116,6 +114,11 @@ function frameStackIteratee(frame: StackFrame) {
116114
return frame;
117115
}
118116

117+
function beforeSendLog(log: Log) {
118+
console.log(`[${log.level}]: ${log.message}`);
119+
return log;
120+
}
121+
119122

120123
// OpenTelemetry Loader
121124
if(cli) {

src/utils/eventLogger.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export async function initialize(channel: Channel) {
2222
type: "Error",
2323
message: "System attempted to initialize log service twice"
2424
});
25-
return console.log("Log channel already initialized!");
2625
}
2726
if(!(channel instanceof TextChannel))
2827
throw new Error("[Logger]: Attempted to initialize log channel with a non-text channel");
@@ -37,7 +36,7 @@ export async function initialize(channel: Channel) {
3736
export async function sendLog(log: LogData) {
3837
// Queue the log if the channel is not initialized
3938
if(!_channel) {
40-
console.debug(`Log added to pre-initialization queue: ${log.message}`);
39+
logger.debug(`Log added to pre-initialization queue: ${log.message}`);
4140
_logQueues.push(log);
4241
return;
4342
}

0 commit comments

Comments
 (0)