Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

updated logs

rafaelsideguide309728a4820a
diff --git a/apps/api/src/controllers/crawl-status.ts b/apps/api/src/controllers/crawl-status.ts
index a55003ccc..5aafa4333 100644
--- a/apps/api/src/controllers/crawl-status.ts
+++ b/apps/api/src/controllers/crawl-status.ts
@@ -4,6 +4,7 @@ import { RateLimiterMode } from "../../src/types";
import { addWebScraperJob } from "../../src/services/queue-jobs";
import { getWebScraperQueue } from "../../src/services/queue-service";
import { supabaseGetJobById } from "../../src/lib/supabase-jobs";
+import { Logger } from "../../src/lib/logger";
export async function crawlStatusController(req: Request, res: Response) {
try {
@@ -44,7 +45,7 @@ export async function crawlStatusController(req: Request, res: Response) {
partial_data: jobStatus == 'completed' ? [] : partialDocs,
});
} catch (error) {
- console.error(error);
+ Logger.error(error);
return res.status(500).json({ error: error.message });
}
}
diff --git a/apps/api/src/controllers/crawl.ts b/apps/api/src/controllers/crawl.ts
index 89358fcc2..614a59284 100644
--- a/apps/api/src/controllers/crawl.ts
+++ b/apps/api/src/controllers/crawl.ts
@@ -10,6 +10,7 @@ import { logCrawl } from "../../src/services/logging/crawl_log";
import { validateIdempotencyKey } from "../../src/services/idempotency/validate";
import { createIdempotencyKey } from "../../src/services/idempotency/create";
import { defaultCrawlPageOptions, defaultCrawlerOptions, defaultOrigin } from "../../src/lib/default-values";
+import { Logger } from "../../src/lib/logger";
export async function crawlController(req: Request, res: Response) {
try {
@@ -30,7 +31,7 @@ export async function crawlController(req: Request, res: Response) {
try {
createIdempotencyKey(req);
} catch (error) {
- console.error(error);
+ Logger.error(error);
return res.status(500).json({ error: error.message });
}
}
@@ -83,7 +84,7 @@ export async function crawlController(req: Request, res: Response) {
documents: docs,
});
} catch (error) {
- console.error(error);
+ Logger.error(error);
return res.status(500).json({ error: error.message });
}
}
@@ -101,7 +102,7 @@ export async function crawlController(req: Request, res: Response) {
res.json({ jobId: job.id });
} catch (error) {
- console.error(error);
+ Logger.error(error);
return res.status(500).json({ error: error.message });
}
}
diff --git a/apps/api/src/controllers/crawlPreview.ts b/apps/api/src/controllers/crawlPreview.ts
index 2c3dc4eac..7c5c804d0 100644
--- a/apps/api/src/controllers/crawlPreview.ts
+++ b/apps/api/src/controllers/crawlPreview.ts
@@ -3,6 +3,7 @@ import { authenticateUser } from "./auth";
import { RateLimiterMode } from "../../src/types";
import { addWebScraperJob } from "../../src/services/queue-jobs";
import { isUrlBlocked } from "../../src/scraper/WebScraper/utils/blocklist";
+import { Logger } from "../../src/lib/logger";
export async function crawlPreviewController(req: Request, res: Response) {
try {
@@ -39,7 +40,7 @@ export async function crawlPreviewController(req: Request, res: Response) {
res.json({ jobId: job.id });
} catch (error) {
- console.error(error);
+ Logger.error(error);
return res.status(500).json({ error: error.message });
}
}
diff --git a/apps/api/src/controllers/scrape.ts b/apps/api/src/controllers/scrape.ts
index fb57e41d1..615f0c0e3 100644
--- a/apps/api/src/controllers/scrape.ts
+++ b/apps/api/src/controllers/scrape.ts
@@ -9,6 +9,7 @@ import { Document } from "../lib/entities";
import { isUrlBlocked } from "../scraper/WebScraper/utils/blocklist"; // Import the isUrlBlocked function
import { numTokensFromString } from '../lib/LLM-extraction/helpers';
import { defaultPageOptions, defaultExtractorOptions, defaultTimeout, defaultOrigin } from '../lib/default-values';
+import { Logger } from '../lib/logger';
export async function scrapeHelper(
req: Request,
@@ -112,7 +113,7 @@ export async function scrapeController(req: Request, res: Response) {
return res.status(402).json({ error: "Insufficient credits" });
}
} catch (error) {
- console.error(error);
+ Logger.error(error);
earlyReturn = true;
return res.status(402).json({ error: "Error checking team credits. Please contact [email protected] for help." });
}
@@ -188,7 +189,7 @@ export async function scrapeController(req: Request, res: Response) {
return res.status(result.returnCode).json(result);
} catch (error) {
- console.error(error);
+ Logger.error(error);
return res.status(500).json({ error: error.message });
}
}
diff --git a/apps/api/src/controllers/search.ts b/apps/api/src/controllers/search.ts
index 8cb6d55b1..adacb766b 100644
--- a/apps/api/src/controllers/search.ts
+++ b/apps/api/src/controllers/search.ts
@@ -7,6 +7,7 @@ import { logJob } from "../services/logging/log_job";
import { PageOptions, SearchOptions } from "../lib/entities";
import { search } from "../search";
import { isUrlBlocked } from "../scraper/WebScraper/utils/blocklist";
+import { Logger } from "../lib/logger";
export async function searchHelper(
req: Request,
@@ -155,7 +156,7 @@ export async function searchController(req: Request, res: Response) {
return res.status(402).json({ error: "Insufficient credits" });
}
} catch (error) {
- console.error(error);
+ Logger.error(error);
return res.status(500).json({ error: "Internal server error" });
}
const startTime = new Date().getTime();
@@ -183,7 +184,7 @@ export async function searchController(req: Request, res: Response) {
});
return res.status(result.returnCode).json(result);
} catch (error) {
- console.error(error);
+ Logger.error(error);
return res.status(500).json({ error: error.message });
}
}
diff --git a/apps/api/src/controllers/status.ts b/apps/api/src/controllers/status.ts
index 231885f4e..3d7fccbb0 100644
--- a/apps/api/src/controllers/status.ts
+++ b/apps/api/src/controllers/status.ts
@@ -1,6 +1,7 @@
import { Request, Response } from "express";
import { getWebScraperQueue } from "../../src/services/queue-service";
import { supabaseGetJobById } from "../../src/lib/supabase-jobs";
+import { Logger } from "../../src/lib/logger";
export async function crawlJobStatusPreviewController(req: Request, res: Response) {
try {
@@ -35,7 +36,7 @@ export async function crawlJobStatusPreviewController(req: Request, res: Respons
partial_data: jobStatus == 'completed' ? [] : partialDocs,
});
} catch (error) {
- console.error(error);
+ Logger.error(error);
return res.status(500).json({ error: error.message });
}
}
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index 700cc98e2..98243756b 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -83,9 +83,9 @@ if (cluster.isMaster) {
function startServer(port = DEFAULT_PORT) {
const server = app.listen(Number(port), HOST, () => {
Logger.info(`Worker ${process.pid} listening on port ${port}`);
- // Logger.info(
- // `For the UI, open: http://${HOST}:${port}/admin/${process.env.BULL_AUTH_KEY}/queues`
- // );
+ Logger.info(
+ `For the Queue UI, open: http://${HOST}:${port}/admin/${process.env.BULL_AUTH_KEY}/queues`
+ );
});
return server;
}
diff --git a/apps/api/src/lib/LLM-extraction/index.ts b/apps/api/src/lib/LLM-extraction/index.ts
index 2156fb3c4..85a7e9953 100644
--- a/apps/api/src/lib/LLM-extraction/index.ts
+++ b/apps/api/src/lib/LLM-extraction/index.ts
@@ -4,6 +4,7 @@ const ajv = new Ajv(); // Initialize AJV for JSON schema validation
import { generateOpenAICompletions } from "./models";
import { Document, ExtractorOptions } from "../entities";
+import { Logger } from "../logger";
// Generate completion using OpenAI
export async function generateCompletions(
@@ -44,7 +45,7 @@ export async function generateCompletions(
return completionResult;
} catch (error) {
- console.error(`Error generating completions: ${error}`);
+ Logger.error(`Error generating completions: ${error}`);
throw new Error(`Error generating completions: ${error.message}`);
}
default:
diff --git a/apps/api/src/lib/withAuth.ts b/apps/api/src/lib/withAuth.ts
index ea5aa4d80..353c144be 100644
--- a/apps/api/src/lib/withAuth.ts
+++ b/apps/api/src/lib/withAuth.ts
@@ -1,4 +1,5 @@
import { AuthResponse } from "../../src/types";
+import { Logger } from "./logger";
let warningCount = 0;
@@ -8,7 +9,7 @@ export function withAuth<T extends AuthResponse, U extends any[]>(
return async function (...args: U): Promise<T> {
if (process.env.USE_DB_AUTHENTICATION === "false") {
if (warningCount < 5) {
- console.warn("WARNING - You're bypassing authentication");
+ Logger.warn("You're bypassing authentication");
warningCount++;
}
return { success: true } as T;
@@ -16,7 +17,7 @@ export function withAuth<T extends AuthResponse, U extends any[]>(
try {
return await originalFunction(...args);
} catch (error) {
- console.error("Error in withAuth function: ", error);
+ Logger.error(`Error in withAuth function: ${error}`);
return { success: false, error: error.message } as T;
}
}
diff --git a/apps/api/src/scraper/WebScraper/utils/blocklist.ts b/apps/api/src/scraper/WebScraper/utils/blocklist.ts
index 633fd5d09..0bdf9876f 100644
--- a/apps/api/src/scraper/WebScraper/utils/blocklist.ts
+++ b/apps/api/src/scraper/WebScraper/utils/blocklist.ts
@@ -1,3 +1,5 @@
+import { Logger } from "../../../lib/logger";
+
const socialMediaBlocklist = [
'facebook.com',
'x.com',
@@ -59,7 +61,7 @@ export function isUrlBlocked(url: string): boolean {
return isBlocked;
} catch (e) {
// If an error occurs (e.g., invalid URL), return false
- console.error(`Error parsing the following URL: ${url}`);
+ Logger.error(`Error parsing the following URL: ${url}`);
return false;
}
}
diff --git a/apps/api/src/scraper/WebScraper/utils/imageDescription.ts b/apps/api/src/scraper/WebScraper/utils/imageDescription.ts
index fb8f65d94..318c23404 100644
--- a/apps/api/src/scraper/WebScraper/utils/imageDescription.ts
+++ b/apps/api/src/scraper/WebScraper/utils/imageDescription.ts
@@ -1,5 +1,6 @@
import Anthropic from '@anthropic-ai/sdk';
import axios from 'axios';
+import { Logger } from '../../../lib/logger';
export async function getImageDescription(
imageUrl: string,
@@ -82,7 +83,7 @@ export async function getImageDescription(
}
}
} catch (error) {
- console.error("Error generating image alt text:", error?.message);
+ Logger.error(`Error generating image alt text: ${error}`);
return "";
}
}
diff --git a/apps/api/src/scraper/WebScraper/utils/metadata.ts b/apps/api/src/scraper/WebScraper/utils/metadata.ts
index 3f2052c03..9496d5697 100644
--- a/apps/api/src/scraper/WebScraper/utils/metadata.ts
+++ b/apps/api/src/scraper/WebScraper/utils/metadata.ts
@@ -1,4 +1,6 @@
import { CheerioAPI } from "cheerio";
+import { Logger } from "../../../lib/logger";
+
interface Metadata {
title?: string;
description?: string;
@@ -105,7 +107,7 @@ export function extractMetadata(soup: CheerioAPI, url: string): Metadata {
dctermsCreated = soup('meta[name="dcterms.created"]').attr("content") || null;
} catch (error) {
- console.error("Error extracting metadata:", error);
+ Logger.error(`Error extracting metadata: ${error}`);
}
return {
diff --git a/apps/api/src/scraper/WebScraper/utils/replacePaths.ts b/apps/api/src/scraper/WebScraper/utils/replacePaths.ts
index 25b43f0ae..f84db63f6 100644
--- a/apps/api/src/scraper/WebScraper/utils/replacePaths.ts
+++ b/apps/api/src/scraper/WebScraper/utils/replacePaths.ts
@@ -1,3 +1,4 @@
+import { Logger } from "../../../lib/logger";
import { Document } from "../../../lib/entities";
export const replacePathsWithAbsolutePaths = (documents: Document[]): Document[] => {
@@ -39,7 +40,7 @@ export const replacePathsWithAbsolutePaths = (documents: Document[]): Document[]
return documents;
} catch (error) {
- console.error("Error replacing paths with absolute paths", error);
+ Logger.debug(`Error replacing paths with absolute paths: ${error}`);
return documents;
}
};
@@ -78,7 +79,7 @@ export const replaceImgPathsWithAbsolutePaths = (documents: Document[]): Documen
return documents;
} catch (error) {
- console.error("Error replacing img paths with absolute paths", error);
+ Logger.error(`Error replacing img paths with absolute paths: ${error}`);
return documents;
}
};
\ No newline at end of file
diff --git a/apps/api/src/scraper/WebScraper/utils/utils.ts b/apps/api/src/scraper/WebScraper/utils/utils.ts
index 3aa021a61..dd5906b09 100644
--- a/apps/api/src/scraper/WebScraper/utils/utils.ts
+++ b/apps/api/src/scraper/WebScraper/utils/utils.ts
@@ -1,5 +1,6 @@
import axios from "axios";
import * as cheerio from "cheerio";
+import { Logger } from "../../../lib/logger";
export async function attemptScrapWithRequests(
@@ -9,13 +10,13 @@ export async function attemptScrapWithRequests(
const response = await axios.get(urlToScrap, { timeout: 15000 });
if (!response.data) {
- console.log("Failed normal requests as well");
+ Logger.debug("Failed normal requests as well");
return null;
}
return response.data;
} catch (error) {
- console.error(`Error in attemptScrapWithRequests: ${error}`);
+ Logger.debug(`Error in attemptScrapWithRequests: ${error}`);
return null;
}
}
diff --git a/apps/api/src/search/googlesearch.ts b/apps/api/src/search/googlesearch.ts
index 6bfa1a397..060f4bd8d 100644
--- a/apps/api/src/search/googlesearch.ts
+++ b/apps/api/src/search/googlesearch.ts
@@ -2,6 +2,7 @@ import axios from 'axios';
import * as cheerio from 'cheerio';
import * as querystring from 'querystring';
import { SearchResult } from '../../src/lib/entities';
+import { Logger } from '../../src/lib/logger';
const _useragent_list = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0',
@@ -96,7 +97,7 @@ export async function google_search(term: string, advanced = false, num_results
await new Promise(resolve => setTimeout(resolve, sleep_interval * 1000));
} catch (error) {
if (error.message === 'Too many requests') {
- console.warn('Too many requests, breaking the loop');
+ Logger.warn('Too many requests, breaking the loop');
break;
}
throw error;
@@ -107,7 +108,7 @@ export async function google_search(term: string, advanced = false, num_results
}
}
if (attempts >= maxAttempts) {
- console.warn('Max attempts reached, breaking the loop');
+ Logger.warn('Max attempts reached, breaking the loop');
}
return results
}
diff --git a/apps/api/src/search/index.ts b/apps/api/src/search/index.ts
index 88cbf812d..f5bc06e30 100644
--- a/apps/api/src/search/index.ts
+++ b/apps/api/src/search/index.ts
@@ -1,3 +1,4 @@
+import { Logger } from "../../src/lib/logger";
import { SearchResult } from "../../src/lib/entities";
import { google_search } from "./googlesearch";
import { serper_search } from "./serper";
@@ -47,7 +48,7 @@ export async function search({
timeout
);
} catch (error) {
- console.error("Error in search function: ", error);
+ Logger.error(`Error in search function: ${error}`);
return []
}
// if process.env.SERPER_API_KEY is set, use serper
diff --git a/apps/api/src/services/alerts/index.ts b/apps/api/src/services/alerts/index.ts
index 1cfb5906c..88b3c726b 100644
--- a/apps/api/src/services/alerts/index.ts
+++ b/apps/api/src/services/alerts/index.ts
@@ -1,3 +1,4 @@
+import { Logger } from "../../../src/lib/logger";
import { getWebScraperQueue } from "../queue-service";
import { sendSlackWebhook } from "./slack";
@@ -9,13 +10,13 @@ export async function checkAlerts() {
process.env.ALERT_NUM_ACTIVE_JOBS &&
process.env.ALERT_NUM_WAITING_JOBS
) {
- console.info("Initializing alerts");
+ Logger.info("Initializing alerts");
const checkActiveJobs = async () => {
try {
const webScraperQueue = getWebScraperQueue();
const activeJobs = await webScraperQueue.getActiveCount();
if (activeJobs > Number(process.env.ALERT_NUM_ACTIVE_JOBS)) {
- console.warn(
+ Logger.warn(
`Alert: Number of active jobs is over ${process.env.ALERT_NUM_ACTIVE_JOBS}. Current active jobs: ${activeJobs}.`
);
sendSlackWebhook(
@@ -23,12 +24,12 @@ export async function checkAlerts() {
true
);
} else {
- console.info(
+ Logger.info(
`Number of active jobs is under ${process.env.ALERT_NUM_ACTIVE_JOBS}. Current active jobs: ${activeJobs}`
);
}
} catch (error) {
- console.error("Failed to check active jobs:", error);
+ Logger.error(`Failed to check active jobs: ${error}`);
}
};
@@ -38,7 +39,7 @@ export async function checkAlerts() {
const paused = await webScraperQueue.getPausedCount();
if (waitingJobs !== paused && waitingJobs > Number(process.env.ALERT_NUM_WAITING_JOBS)) {
- console.warn(
+ Logger.warn(
`Alert: Number of waiting jobs is over ${process.env.ALERT_NUM_WAITING_JOBS}. Current waiting jobs: ${waitingJobs}.`
);
sendSlackWebhook(
@@ -57,6 +58,6 @@ export async function checkAlerts() {
// setInterval(checkAll, 10000); // Run every
}
} catch (error) {
- console.error("Failed to initialize alerts:", error);
+ Logger.error(`Failed to initialize alerts: ${error}`);
}
}
diff --git a/apps/api/src/services/alerts/slack.ts b/apps/api/src/services/alerts/slack.ts
index f65035b1a..89629df74 100644
--- a/apps/api/src/services/alerts/slack.ts
+++ b/apps/api/src/services/alerts/slack.ts
@@ -1,4 +1,5 @@
import axios from "axios";
+import { Logger } from "../../../src/lib/logger";
export async function sendSlackWebhook(
message: string,
@@ -16,8 +17,8 @@ export async function sendSlackWebhook(
"Content-Type": "application/json",
},
});
- console.log("Webhook sent successfully:", response.data);
+ Logger.log("Webhook sent successfully:", response.data);
} catch (error) {
- console.error("Error sending webhook:", error);
+ Logger.error(`Error sending webhook: ${error}`);
}
}
diff --git a/apps/api/src/services/billing/credit_billing.ts b/apps/api/src/services/billing/credit_billing.ts
index 6d0f9a69c..9369cdbbb 100644
--- a/apps/api/src/services/billing/credit_billing.ts
+++ b/apps/api/src/services/billing/credit_billing.ts
@@ -263,14 +263,14 @@ export async function supaCheckTeamCredits(team_id: string, credits: number) {
});
if (creditUsageError) {
- console.error("Error calculating credit usage:", creditUsageError);
+ Logger.error(`Error calculating credit usage: ${creditUsageError}`);
}
if (creditUsages && creditUsages.length > 0) {
totalCreditsUsed = creditUsages[0].total_credits_used;
}
} catch (error) {
- console.error("Error calculating credit usage:", error);
+ Logger.error(`Error calculating credit usage: ${error}`);
}
// Adjust total credits used by subtracting coupon value
diff --git a/apps/api/src/services/idempotency/create.ts b/apps/api/src/services/idempotency/create.ts
index ec3e18e75..291e77d91 100644
--- a/apps/api/src/services/idempotency/create.ts
+++ b/apps/api/src/services/idempotency/create.ts
@@ -1,5 +1,6 @@
import { Request } from "express";
import { supabase_service } from "../supabase";
+import { Logger } from "../../../src/lib/logger";
export async function createIdempotencyKey(
req: Request,
@@ -14,7 +15,7 @@ export async function createIdempotencyKey(
.insert({ key: idempotencyKey });
if (error) {
- console.error("Failed to create idempotency key:", error);
+ Logger.error(`Failed to create idempotency key: ${error}`);
throw error;
}
diff --git a/apps/api/src/services/idempotency/validate.ts b/apps/api/src/services/idempotency/validate.ts
index 1ca348bbc..4d58a31d6 100644
--- a/apps/api/src/services/idempotency/validate.ts
+++ b/apps/api/src/services/idempotency/validate.ts
@@ -1,6 +1,7 @@
import { Request } from "express";
import { supabase_service } from "../supabase";
import { validate as isUuid } from 'uuid';
+import { Logger } from "../../../src/lib/logger";
export async function validateIdempotencyKey(
req: Request,
@@ -13,7 +14,7 @@ export async function validateIdempotencyKey(
// Ensure idempotencyKey is treated as a string
const key = Array.isArray(idempotencyKey) ? idempotencyKey[0] : idempotencyKey;
if (!isUuid(key)) {
- console.error("Invalid idempotency key provided in the request headers.");
+ Logger.debug("Invalid idempotency key provided in the request headers.");
return false;
}
@@ -23,7 +24,7 @@ export async function validateIdempotencyKey(
.eq("key", idempotencyKey);
if (error) {
- console.error(error);
+ Logger.error(`Error validating idempotency key: ${error}`);
}
if (!data || data.length === 0) {
diff --git a/apps/api/src/services/logging/crawl_log.ts b/apps/api/src/services/logging/crawl_log.ts
index 1224bd440..68008e023 100644
--- a/apps/api/src/services/logging/crawl_log.ts
+++ b/apps/api/src/services/logging/crawl_log.ts
@@ -1,4 +1,5 @@
import { supabase_service } from "../supabase";
+import { Logger } from "../../../src/lib/logger";
import "dotenv/config";
export async function logCrawl(job_id: string, team_id: string) {
@@ -13,7 +14,7 @@ export async function logCrawl(job_id: string, team_id: string) {
},
]);
} catch (error) {
- console.error("Error logging crawl job:\n", error);
+ Logger.error(`Error logging crawl job to supabase:\n${error}`);
}
}
}
diff --git a/apps/api/src/services/logging/scrape_log.ts b/apps/api/src/services/logging/scrape_log.ts
index b99d99b4b..208159da0 100644
--- a/apps/api/src/services/logging/scrape_log.ts
+++ b/apps/api/src/services/logging/scrape_log.ts
@@ -8,6 +8,10 @@ export async function logScrape(
scrapeLog: ScrapeLog,
pageOptions?: PageOptions
) {
+ if (process.env.USE_DB_AUTHENTICATION === "false") {
+ Logger.debug("Skipping logging scrape to Supabase");
+ return;
+ }
try {
// Only log jobs in production
// if (process.env.ENV !== "production") {
diff --git a/apps/api/src/services/notification/email_notification.ts b/apps/api/src/services/notification/email_notification.ts
index e5102acd6..d7cd3de0f 100644
--- a/apps/api/src/services/notification/email_notification.ts
+++ b/apps/api/src/services/notification/email_notification.ts
@@ -2,6 +2,7 @@ import { supabase_service } from "../supabase";
import { withAuth } from "../../lib/withAuth";
import { Resend } from "resend";
import { NotificationType } from "../../types";
+import { Logger } from "../../../src/lib/logger";
const emailTemplates: Record<
NotificationType,
@@ -52,11 +53,11 @@ async function sendEmailNotification(
});
if (error) {
- console.error("Error sending email: ", error);
+ Logger.debug(`Error sending email: ${error}`);
return { success: false };
}
} catch (error) {
- console.error("Error sending email (2): ", error);
+ Logger.debug(`Error sending email (2): ${error}`);
return { success: false };
}
}
@@ -79,7 +80,7 @@ export async function sendNotificationInternal(
.lte("sent_date", endDateString);
if (error) {
- console.error("Error fetching notifications: ", error);
+ Logger.debug(`Error fetching notifications: ${error}`);
return { success: false };
}
@@ -93,7 +94,7 @@ export async function sendNotificationInternal(
.eq("team_id", team_id);
if (emailsError) {
- console.error("Error fetching emails: ", emailsError);
+ Logger.debug(`Error fetching emails: ${emailsError}`);
return { success: false };
}
@@ -112,7 +113,7 @@ export async function sendNotificationInternal(
]);
if (insertError) {
- console.error("Error inserting notification record: ", insertError);
+ Logger.debug(`Error inserting notification record: ${insertError}`);
return { success: false };
}
diff --git a/apps/api/src/services/posthog.ts b/apps/api/src/services/posthog.ts
index 5ec16e2e9..a74198836 100644
--- a/apps/api/src/services/posthog.ts
+++ b/apps/api/src/services/posthog.ts
@@ -1,5 +1,6 @@
import { PostHog } from 'posthog-node';
import "dotenv/config";
+import { Logger } from '../../src/lib/logger';
export default function PostHogClient() {
const posthogClient = new PostHog(process.env.POSTHOG_API_KEY, {
@@ -19,7 +20,7 @@ class MockPostHog {
export const posthog = process.env.POSTHOG_API_KEY
? PostHogClient()
: (() => {
- console.warn(
+ Logger.warn(
"POSTHOG_API_KEY is not provided - your events will not be logged. Using MockPostHog as a fallback. See posthog.ts for more."
);
return new MockPostHog();
diff --git a/apps/api/src/services/supabase.ts b/apps/api/src/services/supabase.ts
index fa6404d78..d34f7b521 100644
--- a/apps/api/src/services/supabase.ts
+++ b/apps/api/src/services/supabase.ts
@@ -1,4 +1,5 @@
import { createClient, SupabaseClient } from "@supabase/supabase-js";
+import { Logger } from "../lib/logger";
// SupabaseService class initializes the Supabase client conditionally based on environment variables.
class SupabaseService {
@@ -10,13 +11,13 @@ class SupabaseService {
// Only initialize the Supabase client if both URL and Service Token are provided.
if (process.env.USE_DB_AUTHENTICATION === "false") {
// Warn the user that Authentication is disabled by setting the client to null
- console.warn(
- "\x1b[33mAuthentication is disabled. Supabase client will not be initialized.\x1b[0m"
+ Logger.warn(
+ "Authentication is disabled. Supabase client will not be initialized."
);
this.client = null;
} else if (!supabaseUrl || !supabaseServiceToken) {
- console.error(
- "\x1b[31mSupabase environment variables aren't configured correctly. Supabase client will not be initialized. Fix ENV configuration or disable DB authentication with USE_DB_AUTHENTICATION env variable\x1b[0m"
+ Logger.error(
+ "Supabase environment variables aren't configured correctly. Supabase client will not be initialized. Fix ENV configuration or disable DB authentication with USE_DB_AUTHENTICATION env variable"
);
} else {
this.client = createClient(supabaseUrl, supabaseServiceToken);
@@ -35,10 +36,15 @@ export const supabase_service: SupabaseClient = new Proxy(
new SupabaseService(),
{
get: function (target, prop, receiver) {
+ if (process.env.USE_DB_AUTHENTICATION === "false") {
+ Logger.debug(
+ "Attempted to access Supabase client when it's not configured."
+ );
+ }
const client = target.getClient();
// If the Supabase client is not initialized, intercept property access to provide meaningful error feedback.
if (client === null) {
- console.error(
+ Logger.error(
"Attempted to access Supabase client when it's not configured."
);
return () => {
diff --git a/apps/api/src/services/webhook.ts b/apps/api/src/services/webhook.ts
index 183785465..2fa6cdcd5 100644
--- a/apps/api/src/services/webhook.ts
+++ b/apps/api/src/services/webhook.ts
@@ -1,3 +1,4 @@
+import { Logger } from "../../src/lib/logger";
import { supabase_service } from "./supabase";
export const callWebhook = async (teamId: string, jobId: string,data: any) => {
@@ -15,10 +16,7 @@ export const callWebhook = async (teamId: string, jobId: string,data: any) => {
.eq("team_id", teamId)
.limit(1);
if (error) {
- console.error(
- `Error fetching webhook URL for team ID: ${teamId}`,
- error.message
- );
+ Logger.error(`Error fetching webhook URL for team ID: ${teamId}, error: ${error.message}`);
return null;
}
@@ -53,9 +51,6 @@ export const callWebhook = async (teamId: string, jobId: string,data: any) => {
}),
});
} catch (error) {
- console.error(
- `Error sending webhook for team ID: ${teamId}`,
- error.message
- );
+ Logger.error(`Error sending webhook for team ID: ${teamId}, error: ${error.message}`);
}
};
diff --git a/apps/test-suite/utils/supabase.ts b/apps/test-suite/utils/supabase.ts
index aa19a8c9b..dcefa38cb 100644
--- a/apps/test-suite/utils/supabase.ts
+++ b/apps/test-suite/utils/supabase.ts
@@ -1,5 +1,7 @@
import { createClient, SupabaseClient } from "@supabase/supabase-js";
import "dotenv/config";
+import { Logger } from "../../api/src/lib/logger";
+
// SupabaseService class initializes the Supabase client conditionally based on environment variables.
class SupabaseService {
private client: SupabaseClient | null = null;
@@ -10,13 +12,13 @@ class SupabaseService {
// Only initialize the Supabase client if both URL and Service Token are provided.
if (process.env.USE_DB_AUTHENTICATION === "false") {
// Warn the user that Authentication is disabled by setting the client to null
- console.warn(
- "\x1b[33mAuthentication is disabled. Supabase client will not be initialized.\x1b[0m"
+ Logger.warn(
+ "Authentication is disabled. Supabase client will not be initialized."
);
this.client = null;
} else if (!supabaseUrl || !supabaseServiceToken) {
- console.error(
- "\x1b[31mSupabase environment variables aren't configured correctly. Supabase client will not be initialized. Fix ENV configuration or disable DB authentication with USE_DB_AUTHENTICATION env variable\x1b[0m"
+ Logger.error(
+ "Supabase environment variables aren't configured correctly. Supabase client will not be initialized. Fix ENV configuration or disable DB authentication with USE_DB_AUTHENTICATION env variable"
);
} else {
this.client = createClient(supabaseUrl, supabaseServiceToken);
@@ -35,10 +37,15 @@ export const supabase_service: SupabaseClient = new Proxy(
new SupabaseService(),
{
get: function (target, prop, receiver) {
+ if (process.env.USE_DB_AUTHENTICATION === "false") {
+ Logger.debug(
+ "Attempted to access Supabase client when it's not configured."
+ );
+ }
const client = target.getClient();
// If the Supabase client is not initialized, intercept property access to provide meaningful error feedback.
if (client === null) {
- console.error(
+ Logger.error(
"Attempted to access Supabase client when it's not configured."
);
return () => {