-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(logging): replace console.warn with logger in stars API route #3514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,9 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import { NextResponse } from 'next/server' | ||||||||||||||||||||||||||||||||||||||||||
| import { createLogger } from '@sim/logger' | ||||||||||||||||||||||||||||||||||||||||||
| import { env } from '@/lib/core/config/env' | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const logger = createLogger('StarsAPI') | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| function formatStarCount(num: number): string { | ||||||||||||||||||||||||||||||||||||||||||
| if (num < 1000) return String(num) | ||||||||||||||||||||||||||||||||||||||||||
| const formatted = (Math.round(num / 100) / 10).toFixed(1) | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -22,14 +25,14 @@ export async function GET() { | |||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if (!response.ok) { | ||||||||||||||||||||||||||||||||||||||||||
| console.warn('GitHub API request failed:', response.status) | ||||||||||||||||||||||||||||||||||||||||||
| logger.warn('GitHub API request failed:', response.status) | ||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json({ stars: formatStarCount(19400) }) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const data = await response.json() | ||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json({ stars: formatStarCount(Number(data?.stargazers_count ?? 19400)) }) | ||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||
| console.warn('Error fetching GitHub stars:', error) | ||||||||||||||||||||||||||||||||||||||||||
| logger.warn('Error fetching GitHub stars:', error) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warn-level logs are suppressed in production by default The This means GitHub API failures — both non-OK responses and thrown exceptions — will be invisible in production logs by default. Consider whether these should be elevated to
Suggested change
and
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| return NextResponse.json({ stars: formatStarCount(19400) }) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Production warnings silently suppressed by logger level filtering
Medium Severity
Switching from
console.warntologger.warnsilently suppresses these warnings in production. The@sim/loggerdefaults toLogLevel.ERRORin production, soWARN-level messages are filtered out unlessLOG_LEVELis explicitly overridden. Previously,console.warnalways emitted output. GitHub API failures and fetch errors will now go unnoticed in production logs.Additional Locations (1)
apps/sim/app/api/stars/route.ts#L34-L35