Skip to content

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

@Nefcanto

Description

@Nefcanto

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions