Cli: Disable console logging to the terminal

Created on 15 Oct 2019  路  9Comments  路  Source: react-native-community/cli

In the new version of react-native-cli, the console.log output is forwarded to the terminal when react-native start is used.

While there are many situations when this is very convenient and helps with debugging, I would like to know if there is a way to disable it: I have created a custom logger for all network calls, that leverages console.log styling options to provide a nice reading experience for large objects. The styling doesn't work in the terminal, so I end up with huge unreadable blobs of data that are only making a mess in my terminal.

Is there a way to disable terminal logging, so I can keep debugging in the chrome console while also keeping my terminal as clean as possible?

question

Most helpful comment

Would love to be able to toggle this on/off with a config.

Having all logs going to metro has some big impact on overall app performance when debugging.

This week I spent some decent amount of time debugging some performance issue that was affecting a screen where we have a tiny images list and we also use that screen to upload images to a server.

I could not find what was the cause for that whole screen suddenly being terribly slow and unresponsive. When I suddenly noticed this on a terminal window:

ezgif com-optimize

At first, I was feeling a little bit like Tank in Matrix, but then I remembered:

This screen had a simple console.log for the images array list and each item had the base64 data property for the images and they were between 4 and 8 MB worth of text each.

When all that text was being sent to the console, it eventually eats up all the console buffer and everything started slowing down. Hitting CMD + K (Clear terminal) like crazy while that was happening was the only way to prevent the performance hit. Removing the console.log did the permanent trick but we have lots of scenarios like this where we console.log if we are in DEV environment and it has been a real problem having to go and prune those out because of the performance hit we were having.

As @hayanisaid we also have a huge redux state tree and its also partially being logged for debugging and it was killing us.

Now I'm currently running yarn start > /dev/null to prevent anything from being outputted on console and it runs smoothly again and I can keep my logs.

All 9 comments

+1 to this. Terminal logging provides no formatting nor collapsing of huge elements so It ends up being really annoying if , for example, you end up console.logging some 10k items array.

I have to the same problem, and it's really annoying cuz I'm using redux and the redux logger print all the data store into the console the things that make my terminal crashes

+1

We would have to disable forwarding logs from metro. I guess we can add a flag to handle this use case.

@rickhanlonii isn't this something that you work on as a LogBox project?

Would love to be able to toggle this on/off with a config.

Having all logs going to metro has some big impact on overall app performance when debugging.

This week I spent some decent amount of time debugging some performance issue that was affecting a screen where we have a tiny images list and we also use that screen to upload images to a server.

I could not find what was the cause for that whole screen suddenly being terribly slow and unresponsive. When I suddenly noticed this on a terminal window:

ezgif com-optimize

At first, I was feeling a little bit like Tank in Matrix, but then I remembered:

This screen had a simple console.log for the images array list and each item had the base64 data property for the images and they were between 4 and 8 MB worth of text each.

When all that text was being sent to the console, it eventually eats up all the console buffer and everything started slowing down. Hitting CMD + K (Clear terminal) like crazy while that was happening was the only way to prevent the performance hit. Removing the console.log did the permanent trick but we have lots of scenarios like this where we console.log if we are in DEV environment and it has been a real problem having to go and prune those out because of the performance hit we were having.

As @hayanisaid we also have a huge redux state tree and its also partially being logged for debugging and it was killing us.

Now I'm currently running yarn start > /dev/null to prevent anything from being outputted on console and it runs smoothly again and I can keep my logs.

Any update to this, I would also love to be able to disable the console logs in terminal. I think maybe there should be some option in metro.config.js but apparently there isn't?

All the logging is present in the metro and there is no way to disable it. For now, I was able to get rid of logs by removing their logger using patch-package https://gist.github.com/Esemesek/00b49e8041bb27b6215c2cc8dafb2378. I will move this issue to metro issue tracker.

Was this page helpful?
0 / 5 - 0 ratings