'How can I log my output to .txt file instead of the terminal in Expo?

I am using Expo for my React Native Application. console.log(responseJson) writes the App.js output to the my zsh terminal however my Json gets truncated with the following message.

...(truncated to the first 10000 characters)

I want to be able to view the entire Json by logging the output to a .txt file on my app directory.

Is there a solution or workaround without having to eject my Expo app to ExpoKit?



Solution 1:[1]

Alternative solution:

install json-server

npm install -g json-server

create a new file for logs:

echo '{"logs": []}'> logs.json

start json-server:

json-server logs.json

now in your code you can store:

let veryLargeTextWorks = "1234567890";
    for (let i = 0; i < 11; i++) {
      veryLargeTextWorks += veryLargeTextWorks;
    }
// veryLargeTextWorks.length == 20480
axios.post("http://localhost:3000/logs", {
      date: new Date(),
      msg: veryLargeTextWorks
    });

Solution 2:[2]

I have different solution, you can view complete logs in ScrollView.

You need to save response JSON using useState and then write code like this in ScrollView.

return(<View style={styles.container}>
    <ScrollView>
    <Text>{ JSON.stringify(responseJson) }</Text>
    </ScrollView>
</View>)

I have checked this code. It will show complete logs without any problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tiago Cunha Fernandes
Solution 2 Jaytesh Barange