Skip to content

Commit

Permalink
clean console.logs for the whole codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt committed Dec 6, 2024
1 parent f1e2dcd commit 271591e
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 41 deletions.
4 changes: 2 additions & 2 deletions packages/backend/src/api/v1/data-warehouse/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export async function createNewDatastream(
console.info(`Stream creation initiated. Operation name: ${operation.name}`);

const [response] = await operation.promise();
console.log("Stream created successfully:", response);
console.info("Stream created successfully:", response);

if (typeof operation.result?.name !== "string") {
throw new Error("Stream creation failed:", response);
Expand All @@ -235,7 +235,7 @@ export async function createNewDatastream(

const [updateOperation] =
await datastreamClient.updateStream(updateStreamRequest);
console.log(
console.info(
`Stream update initiated. Operation name: ${updateOperation.name}`,
);
await sql`
Expand Down
8 changes: 4 additions & 4 deletions packages/backend/src/api/v1/evaluations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ evaluations.post(
checklistId,
orgId,
});
console.log(`Task ${count} don with model ${provider.model} done`);
console.info(`Task ${count} don with model ${provider.model} done`);
});
}
}
Expand All @@ -98,14 +98,14 @@ evaluations.post(
queue.on("dequeue", () => {
done++;
const percentDone = (1 - (count - done) / count) * 100;
console.log(`Active: ${done} of ${count} (${percentDone}%)`);
console.debug(`Active: ${done} of ${count} (${percentDone}%)`);
stream.write(JSON.stringify({ percentDone }) + "\n");
});

console.log(`Queue started with ${count} tasks`);
console.debug(`Queue started with ${count} tasks`);

queue.on("end", () => {
console.log("Queue is empty now");
console.debug("Queue is empty now");

stream.write(JSON.stringify({ id: evaluation?.id }) + "\n");

Expand Down
6 changes: 2 additions & 4 deletions packages/backend/src/api/v1/evaluations/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export async function runEval({
orgId,
}: RunEvalParams) {
try {
console.log(`=============================`);
console.log(
console.info(`=============================`);
console.info(
`Running eval for ${provider.model} with variation ${JSON.stringify(variation.variables)} and config ${JSON.stringify(provider.config)}`,
);
const { variables, idealOutput } = variation;
Expand Down Expand Up @@ -120,8 +120,6 @@ export async function runEval({
duration,
})}
`;

console.log(`Eval for ${provider.model} passed: ${passed}`);
} catch (error: any) {
await sql`
insert into evaluation_result ${sql({
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/api/v1/projects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ projects.post(
where project_id = ${projectId}
and type = 'private'
`;

console.log("Private key regenerated", newKey);
}

ctx.status = 200;
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/api/v1/runs/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ async function registerRunEvent(
console.warn(`Error getting parent run user.`);

if (allowRetry) {
console.log(
console.info(
"Retrying insertion in 2s in case parent not inserted yet...",
);

Expand Down Expand Up @@ -534,7 +534,7 @@ export async function processEventsIngestion(
}
}

console.log(`Inserted ${insertedIds.size} run for project ${projectId}`);
console.info(`Inserted ${insertedIds.size} run for project ${projectId}`);
return results;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/api/webhooks/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const router = new Router({
});

async function setupSubscription(object: Stripe.Checkout.Session) {
console.log("🔔 setupSubscription", object);
console.info("🔔 setupSubscription", object);
const { customer, client_reference_id, mode, subscription, metadata } =
object;

Expand Down Expand Up @@ -88,7 +88,7 @@ async function updateSubscription(object: Stripe.Subscription) {
((!plan && !period) ||
(currentOrg.plan === plan && currentOrg.planPeriod === period))
) {
console.log(`🔥 updateSubscription: nothing to update`);
console.error(`🔥 updateSubscription: nothing to update`);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/evaluators/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ async function detectLanguages(texts: string[]): Promise<any> {
return callML("language", { texts });
} catch (error) {
console.error(error);
console.log(texts);
console.error(texts);
}
}
2 changes: 1 addition & 1 deletion packages/backend/src/evaluators/pii.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ async function detectPIIs(
});
} catch (error) {
console.error(error);
console.log(texts);
console.error(texts);
}
}
2 changes: 1 addition & 1 deletion packages/backend/src/evaluators/sentiment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async function analyzeSentiment(
return callML("sentiment", { texts });
} catch (error) {
console.error(error);
console.log(texts);
console.error(texts);
return texts.map(() => null);
}
}
2 changes: 1 addition & 1 deletion packages/backend/src/evaluators/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ async function detectTopics(
});
} catch (error) {
console.error(error);
console.log(texts);
console.error(texts);
}
}
2 changes: 1 addition & 1 deletion packages/backend/src/evaluators/toxicity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ async function detectToxicity(texts: string[]): Promise<any> {
return callML("toxicity", { texts });
} catch (error) {
console.error(error);
console.log(texts);
console.error(texts);
}
}
4 changes: 2 additions & 2 deletions packages/backend/src/jobs/realtime-evaluators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ async function evaluatorJob() {
const runs = await getEvaluatorRuns(evaluator);

if (!runs.length) {
console.log(
console.info(
`Skipping Real-time Evaluator ${evaluator.id} (${i} / ${evaluators.length})`,
);
continue;
}

console.log(
console.info(
`Starting Real-time Evaluator ${evaluator.id} - ${runs.length} runs (${i + 1} / ${evaluators.length})`,
);

Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/jobs/resetUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ async function resetPlaygroundAllowance() {

export default async function resetUsage() {
try {
console.log("[JOB]: resetting AI allowance");
console.info("[JOB]: resetting AI allowance");
await resetPlaygroundAllowance();
} catch (error) {
console.error(error);
}

try {
console.log("[JOB]: updating limited status");
console.info("[JOB]: updating limited status");
await updateLimitedStatus();
} catch (error) {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/jobs/stripeMeters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function stripeCounters() {
FROM org o
WHERE o.stripe_customer IS NOT NULL AND o.plan = 'team' AND o.stripe_subscription IS NOT NULL`;

console.log(`Counting runs for ${orgs.length} orgs`);
console.info(`Counting runs for ${orgs.length} orgs`);

for (const org of orgs) {
// count the number of events in the past hour (each 'run' where 'run.project.org = org.id')
Expand Down
14 changes: 7 additions & 7 deletions packages/backend/src/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const sql = postgres(process.env.DATABASE_URL!, {
application_name: `backend-${isProduction ? "production" : "development"}-${new Date().getTime()}`,
},
debug: process.env.LUNARY_DEBUG ? debugFn : () => {},
onnotice: process.env.LUNARY_DEBUG ? console.log : () => {},
onnotice: process.env.LUNARY_DEBUG ? console.warn : () => {},
});

function debugFn(
Expand All @@ -45,17 +45,17 @@ function debugFn(
query = query.replace(regex, `'${parameters[i]}'`);
}

console.log("connection:", connection);
console.log("query:", query);
console.log("parameters:", parameters);
console.log("paramTypes:", paramTypes);
console.log("-----\n");
console.debug("connection:", connection);
console.debug("query:", query);
console.debug("parameters:", parameters);
console.debug("paramTypes:", paramTypes);
console.debug("-----\n");
}

export async function checkDbConnection() {
try {
await sql`select 1`;
console.log("✅ Connected to database");
console.info("✅ Connected to database");
} catch (error) {
console.error("❌ Could not connect to database");
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function errorMiddleware(ctx: Context, next: Next) {
error: "Error",
message: error.errors[0].message,
};
console.log("ZOD ERROR", error.errors[0]);
console.error("ZOD ERROR", error.errors[0]);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/utils/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export async function runAImodel(
stripe_customer_id: stripeCustomer,
},
})
.then(() => console.log("Metered"))
.then(() => console.info("Metered"))
.catch(console.error);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export default function AreaChartComponent({
...item,
value: formatLargeNumber(Number.parseInt(item.value)),
}));
console.log(filteredPayload);

if (filteredPayload.length === 0) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/components/layout/Analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export default function AnalyticsWrapper({ children }) {
dangerouslySetInnerHTML={{
__html: process.env.NEXT_PUBLIC_CUSTOM_SCRIPT,
}}
onLoad={() => console.log("Custom script loaded.")}
onError={() => console.log("Custom script failed to load.")}
onLoad={() => console.info("Custom script loaded.")}
onError={() => console.info("Custom script failed to load.")}
/>
)}

Expand Down
1 change: 0 additions & 1 deletion packages/frontend/pages/guardrails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function TopicModal() {

const handleSubmit = () => {
// TODO: Implement submission logic
console.log({ name, definition, samplePhrases });
setOpened(false);
};

Expand Down
1 change: 0 additions & 1 deletion packages/frontend/utils/dataHooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ export function buildLogsAPIUrl(data = {}) {
}

export function useLogs(params: any) {
console.log("LOGS");
return useProjectInfiniteSWR(buildLogsAPIUrl(params));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function useTraceUpdate(props: any) {
{},
);
if (Object.keys(changedProps).length > 0) {
console.log("Changed props:", changedProps);
console.info("Changed props:", changedProps);
}
prev.current = props;
});
Expand Down

0 comments on commit 271591e

Please sign in to comment.