T
TanStack11mo ago
like-gold

How do I turn off console logs for server functions?

Is there a setting somewhere in app.config.ts? I couldn't find anything in the documentation
6 Replies
fascinating-indigo
fascinating-indigo11mo ago
I really wanna know this too, I started a post on it today too, but accidentally in the query channel Please ping me if you find out
fascinating-indigo
fascinating-indigo11mo ago
I tracked down where these logs are coming from in the TanStack router here and are not configurable https://github.com/TanStack/router/blob/8e4d1645c23678aae486674b7dda4ef2e130d0a9/packages/start/src/server-handler/index.tsx#L170 Anyway, I found a workaround. Add this to your ssr.tsx at the very top (before imports):
const originalConsoleInfo = console.info
console.info = (...args) => {
if (
!args.length ||
args.some(arg => typeof arg === "string" && (
arg.startsWith("ServerFn") ||
arg.includes("Payload:") ||
!arg.trim()
))
) {
return
}

originalConsoleInfo.apply(console, args)
}
const originalConsoleInfo = console.info
console.info = (...args) => {
if (
!args.length ||
args.some(arg => typeof arg === "string" && (
arg.startsWith("ServerFn") ||
arg.includes("Payload:") ||
!arg.trim()
))
) {
return
}

originalConsoleInfo.apply(console, args)
}
This will filter out all ServerFn logs, Payload messages and empty lines, keeping your console clean during development
GitHub
router/packages/start/src/server-handler/index.tsx at 8e4d1645c2367...
🤖 Fully typesafe Router for React (and friends) w/ built-in caching, 1st class search-param APIs, client-side cache integration and isomorphic rendering. - TanStack/router
like-gold
like-goldOP11mo ago
thanks! @Sajmon will wait for an official solution though, it's just a bit annoying during dev but not intolerable
fascinating-indigo
fascinating-indigo11mo ago
Yeah, for me it was a little bit more annoying because i have my own logging utility and it is bad when they are mixing together
No description
No description
wise-white
wise-white11mo ago
I've took the chance to start contributing and opened a PR for it 😁 https://github.com/TanStack/router/pull/2719
foreign-sapphire
foreign-sapphire7mo ago
Any update on this?

Did you find this page helpful?