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

start: allow disabling server functions logs #2719

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 9 additions & 8 deletions packages/start/src/server-handler/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ export async function handleServerRequest(request: Request, event?: H3Event) {

invariant(typeof serverFnId === 'string', 'Invalid server action')

if (process.env.NODE_ENV === 'development')
console.info(`ServerFn Request: ${serverFnId} - ${serverFnName}`)
if (process.env.NODE_ENV === 'development') console.info()
const shouldLogServerFn =
process.env.NODE_ENV === 'development' &&
process.env.TANSTACK_START_LOG_SERVER_FN_ENABLED !== 'false'

if (shouldLogServerFn)
console.info(`ServerFn Request: ${serverFnId} - ${serverFnName}\n`)

const action = (await getManifest('server').chunks[serverFnId]?.import())?.[
serverFnName
Expand Down Expand Up @@ -157,20 +160,18 @@ export async function handleServerRequest(request: Request, event?: H3Event) {
}
})()

if (process.env.NODE_ENV === 'development')
console.info(`ServerFn Response: ${response.status}`)
if (shouldLogServerFn) console.info(`ServerFn Response: ${response.status}`)

if (response.headers.get('Content-Type') === 'application/json') {
const cloned = response.clone()
const text = await cloned.text()
const payload = text ? JSON.stringify(JSON.parse(text)) : 'undefined'

if (process.env.NODE_ENV === 'development')
if (shouldLogServerFn)
console.info(
` - Payload: ${payload.length > 100 ? payload.substring(0, 100) + '...' : payload}`,
` - Payload: ${payload.length > 100 ? payload.substring(0, 100) + '...' : payload}\n`,
)
}
if (process.env.NODE_ENV === 'development') console.info()

return response
}
Expand Down