yvdevy
yvdevy

Reputation: 25

Is there any way to log errors and info from reactjs app to local file?

I've a requirement that rather than showing info and errors on console I want to enter them into a file

Upvotes: 0

Views: 1727

Answers (1)

Mike Lischke
Mike Lischke

Reputation: 53317

For security reasons you cannot get access to a local file and write to it randomly. The only way to read a file is to ask the user to pick one, using the file open dialog and you can read that only as a whole, without knowing which file the user selected. To write a file you can only have its content written as a whole and the result is handled, as if the user downloaded a file from somehwere (it ends up in the browser's download folder).

What you can do is to continue writing to the console to have the messages shown in the browser's debug console. Additionally, you can write messages to your backend (if you have such functionality) and have that store all of them. You can then offer to download that log from the backend and show it in the UI.

Upvotes: 1

Related Questions