Logging in server route
I wanted to log in server routes but trying to import
@nuxt/kit throws
is there a built-in logger on server?2 Replies
Hi @tpluscode. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
You cannot import
- Use
-
- There is no alternative built-in logger for server routes in the knowledge sources. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
@nuxt/kit in server routes, plugins, or runtime code. Nuxt Kit utilities like useLogger are only available for use inside Nuxt modules (i.e., in your module.ts or similar), not in runtime files such as server routes, composables, or plugins. Attempting to import @nuxt/kit in a server route will throw an error, as you have experienced:
Nuxt Kit usage docs
For logging inside server routes, you can use the standard console.log, console.info, console.warn, or console.error methods. There is no special built-in logger for server routes documented in the official Nuxt docs. The useLogger utility is only for module development, not for runtime/server code.
Example:
Server directory structure and usage
In summary:- Use
console.log for logging in server routes.-
@nuxt/kit and its utilities are not available in runtime/server code.- There is no alternative built-in logger for server routes in the knowledge sources. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@555413648382623754> Kapa.ai is still learning and improving, please let me know how I did by reacting below.