qwik icon indicating copy to clipboard operation
qwik copied to clipboard

[📖] Please provide a section about what is your recommendation to find useless console.logs

Open Nefcanto opened this issue 1 year ago • 4 comments

Suggestion

Using console.log seems to be common. Yet it has a downside. Sometimes it's left unintentionally in the code. When the codebase becomes bigger, then a terminal is littered with logs, but the file and line of code that made that log are not apparent.

One technique that we use is to override console.log to include the stack trace too:

    const originalLog = console.log
    console.log = props => {
        const stack = new Error()
            .stack
            .split("\n")
            .filter(i => !/^.*(\.vite|keycloak|\.main\.jsx).*/.test(i))
        originalLog(stack, props)
    }

Try console.log("something") and you will see a good stack helping you find the place of the left log.

This works when we put it inside a component. But when we want to put it inside the entry.express or entry.dev or entry.preview, then it has no effect.

Please add a section to the documentation explaining your official way of finding useless console.log statements.

Nefcanto avatar Jun 05 '25 10:06 Nefcanto

I guess you could try something similar to this? https://nuxt.com/docs/api/kit/logging

This is not a priority right now to add such a route to the docs so PR very welcome 🍻

maiieul avatar Jun 19 '25 15:06 maiieul

why not simply enable the eslint rule? Not sure such a general recommendation belongs in the qwik docs

wmertens avatar Aug 06 '25 06:08 wmertens

@wmertens, the eslint rule is not effective in this case. We want to keep some of the console.logs and remove others. We need to know what text comes from which console.log. That's effective.

Nefcanto avatar Aug 06 '25 11:08 Nefcanto

Hi! I'd like to try working on this issue if possible. Would it be okay to assign it to me? Thank you!

KyeongJooni avatar Dec 12 '25 16:12 KyeongJooni