Skip to content

Commit 3ee8cc7

Browse files
committed
fix logger issues
1 parent e0519ae commit 3ee8cc7

File tree

6 files changed

+24
-43
lines changed

6 files changed

+24
-43
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Request, Response } from "express";
22
import { supabase_service } from "../../../services/supabase";
33
import { clearACUC } from "../../auth";
4-
import { Logger } from "../../../lib/logger";
4+
import { logger } from "../../../lib/logger";
55

66
export async function acucCacheClearController(req: Request, res: Response) {
77
try {
@@ -12,11 +12,11 @@ export async function acucCacheClearController(req: Request, res: Response) {
1212
.select("*")
1313
.eq("team_id", team_id);
1414

15-
await Promise.all(keys.data.map((x) => clearACUC(x.key)));
15+
await Promise.all((keys.data ?? []).map((x) => clearACUC(x.key)));
1616

1717
res.json({ ok: true });
1818
} catch (error) {
19-
Logger.error(`Error clearing ACUC cache via API route: ${error}`);
19+
logger.error(`Error clearing ACUC cache via API route: ${error}`);
2020
res.status(500).json({ error: "Internal server error" });
2121
}
2222
}

apps/api/src/example.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

apps/api/src/services/billing/auto_charge.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Import necessary dependencies and types
22
import { AuthCreditUsageChunk } from "../../controllers/v1/types";
3-
import { getACUC, setCachedACUC } from "../../controllers/auth";
3+
import { getACUC } from "../../controllers/auth";
44
import { redlock } from "../redlock";
55
import { supabase_service } from "../supabase";
66
import { createPaymentIntent } from "./stripe";
@@ -9,7 +9,7 @@ import { sendNotification } from "../notification/email_notification";
99
import { NotificationType } from "../../types";
1010
import { deleteKey, getValue, setValue } from "../redis";
1111
import { sendSlackWebhook } from "../alerts/slack";
12-
import { Logger } from "../../lib/logger";
12+
import { logger } from "../../lib/logger";
1313

1414
// Define the number of credits to be added during auto-recharge
1515
const AUTO_RECHARGE_CREDITS = 1000;
@@ -32,7 +32,7 @@ export async function autoCharge(
3232
// Another check to prevent race conditions, double charging - cool down of 5 minutes
3333
const cooldownValue = await getValue(cooldownKey);
3434
if (cooldownValue) {
35-
Logger.info(`Auto-recharge for team ${chunk.team_id} is in cooldown period`);
35+
logger.info(`Auto-recharge for team ${chunk.team_id} is in cooldown period`);
3636
return {
3737
success: false,
3838
message: "Auto-recharge is in cooldown period",
@@ -59,7 +59,7 @@ export async function autoCharge(
5959
.single();
6060

6161
if (customersError) {
62-
Logger.error(`Error fetching customer data: ${customersError}`);
62+
logger.error(`Error fetching customer data: ${customersError}`);
6363
return {
6464
success: false,
6565
message: "Error fetching customer data",
@@ -124,7 +124,7 @@ export async function autoCharge(
124124
false,
125125
process.env.SLACK_ADMIN_WEBHOOK_URL
126126
).catch((error) => {
127-
Logger.debug(`Error sending slack notification: ${error}`);
127+
logger.debug(`Error sending slack notification: ${error}`);
128128
});
129129

130130
// Set cooldown for 1 hour
@@ -138,7 +138,7 @@ export async function autoCharge(
138138
chunk: {...chunk, remaining_credits: chunk.remaining_credits + AUTO_RECHARGE_CREDITS},
139139
};
140140
} else {
141-
Logger.error("No Stripe customer ID found for user");
141+
logger.error("No Stripe customer ID found for user");
142142
return {
143143
success: false,
144144
message: "No Stripe customer ID found for user",
@@ -147,7 +147,7 @@ export async function autoCharge(
147147
};
148148
}
149149
} else {
150-
Logger.error("No sub_user_id found in chunk");
150+
logger.error("No sub_user_id found in chunk");
151151
return {
152152
success: false,
153153
message: "No sub_user_id found in chunk",
@@ -165,7 +165,7 @@ export async function autoCharge(
165165

166166
});
167167
} catch (error) {
168-
Logger.error(`Failed to acquire lock for auto-recharge: ${error}`);
168+
logger.error(`Failed to acquire lock for auto-recharge: ${error}`);
169169
return {
170170
success: false,
171171
message: "Failed to acquire lock for auto-recharge",

apps/api/src/services/billing/issue_credits.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Logger } from "../../lib/logger";
1+
import { logger } from "../../lib/logger";
22
import { supabase_service } from "../supabase";
33

44
export async function issueCredits(team_id: string, credits: number) {
55
// Add an entry to supabase coupons
6-
const { data, error } = await supabase_service.from("coupons").insert({
6+
const { error } = await supabase_service.from("coupons").insert({
77
team_id: team_id,
88
credits: credits,
99
status: "active",
@@ -12,7 +12,7 @@ export async function issueCredits(team_id: string, credits: number) {
1212
});
1313

1414
if (error) {
15-
Logger.error(`Error adding coupon: ${error}`);
15+
logger.error(`Error adding coupon: ${error}`);
1616
return false;
1717
}
1818

apps/api/src/services/billing/stripe.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Logger } from "../../lib/logger";
1+
import { logger } from "../../lib/logger";
22
import Stripe from "stripe";
33

44
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY ?? "");
@@ -18,7 +18,7 @@ export async function createPaymentIntent(
1818
try {
1919
const defaultPaymentMethod = await getCustomerDefaultPaymentMethod(customer_id);
2020
if (!defaultPaymentMethod) {
21-
Logger.error(`No default payment method found for customer: ${customer_id}`);
21+
logger.error(`No default payment method found for customer: ${customer_id}`);
2222
return { return_status: "failed", charge_id: "" };
2323
}
2424
const paymentIntent = await stripe.paymentIntents.create({
@@ -33,21 +33,21 @@ export async function createPaymentIntent(
3333
});
3434

3535
if (paymentIntent.status === "succeeded") {
36-
Logger.info(`Payment succeeded for team: ${team_id}`);
36+
logger.info(`Payment succeeded for team: ${team_id}`);
3737
return { return_status: "succeeded", charge_id: paymentIntent.id };
3838
} else if (
3939
paymentIntent.status === "requires_action" ||
4040
paymentIntent.status === "processing" ||
4141
paymentIntent.status === "requires_capture"
4242
) {
43-
Logger.warn(`Payment requires further action for team: ${team_id}`);
43+
logger.warn(`Payment requires further action for team: ${team_id}`);
4444
return { return_status: "requires_action", charge_id: paymentIntent.id };
4545
} else {
46-
Logger.error(`Payment failed for team: ${team_id}`);
46+
logger.error(`Payment failed for team: ${team_id}`);
4747
return { return_status: "failed", charge_id: paymentIntent.id };
4848
}
4949
} catch (error) {
50-
Logger.error(
50+
logger.error(
5151
`Failed to create or confirm PaymentIntent for team: ${team_id}`
5252
);
5353
console.error(error);

apps/api/src/services/system-monitor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import si from 'systeminformation';
22
import { Mutex } from "async-mutex";
33
import os from 'os';
44
import fs from 'fs';
5-
import { Logger } from '../lib/logger';
5+
import { logger } from '../lib/logger';
66

77
const IS_KUBERNETES = process.env.IS_KUBERNETES === "true";
88

@@ -79,7 +79,7 @@ class SystemMonitor {
7979

8080
return memoryUsagePercentage;
8181
} catch (error) {
82-
Logger.error(`Error calculating memory usage: ${error}`);
82+
logger.error(`Error calculating memory usage: ${error}`);
8383
return 0; // Fallback to 0% usage
8484
}
8585
}
@@ -134,7 +134,7 @@ class SystemMonitor {
134134
throw new Error('No CPUs found in cpuset.cpus.effective');
135135
}
136136
} catch (error) {
137-
Logger.warn(`Unable to read cpuset.cpus.effective, defaulting to OS CPUs: ${error}`);
137+
logger.warn(`Unable to read cpuset.cpus.effective, defaulting to OS CPUs: ${error}`);
138138
cpus = os.cpus().map((cpu, index) => index);
139139
}
140140
return cpus.length;
@@ -184,7 +184,7 @@ class SystemMonitor {
184184

185185
return cpuUsagePercentage;
186186
} catch (error) {
187-
Logger.error(`Error calculating CPU usage: ${error}`);
187+
logger.error(`Error calculating CPU usage: ${error}`);
188188
return 0; // Fallback to 0% usage
189189
}
190190
}

0 commit comments

Comments
 (0)