Skip to content
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

chore(api): /api/clean better logging #280

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/api/clean/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ async function cleanupHangQuery(
throw new Error(
`Last cleanup was ${lastCleanup} less than ${QUERY_CLEANUP_MAX_DURATION_SECONDS}s`
)
} else {
console.log('[/api/clean] Starting clean up hang queries')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a logging library instead of console.log

Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).

}

type KillQueryResponse = {
Expand Down Expand Up @@ -97,6 +99,7 @@ async function cleanupHangQuery(

// Nothing to cleanup
if (!killQueryResp || killQueryResp?.rows === 0) {
console.log('[/api/clean] Done, nothing to cleanup')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a logging library instead of console.log

Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).

return {
lastCleanup,
message: 'Nothing to cleanup',
Expand All @@ -108,9 +111,10 @@ async function cleanupHangQuery(
error instanceof Error &&
error.message.includes('Unexpected end of JSON input')
) {
console.log('[/api/clean] Done, nothing to cleanup')
return { lastCleanup, message: 'Nothing to cleanup' }
} else {
console.error(error)
console.error('[/api/clean] Error when killing queries:', error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a logging library instead of console.error

Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).

Suggested change
console.error('[/api/clean] Error when killing queries:', error)
import { Logger } from 'some-logging-library';
const logger = new Logger();
...
logger.error('[/api/clean] Error when killing queries:', error);

throw new Error(`Error when killing queries: ${error}`)
}
}
Expand All @@ -126,7 +130,9 @@ async function cleanupHangQuery(
],
format: 'JSONEachRow',
})
console.log('[/api/clean] LastCleanup event created')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a logging library instead of console.log

Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).

} catch (error) {
console.error("[/api/clean] 'LastCleanup' event creating error:", error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a logging library instead of console.error

Using a logging library can provide more control over log levels and output formats, and can be configured to write to different destinations (e.g., files, external logging services).

throw new Error(`'LastCleanup' event creating error: ${error}`)
}

Expand Down
Loading