How is that possible to create a log file?
Right now I log with console.log() but I need it to be saved.
Never done this before, maybe possible to write the logs in to a txt file in remote location like Onedrive?
CodePudding user response:
Michael, welcome to SO. The only way that I'm aware of saving locally is not what you'd think, as in a file saved to the file system. Within the browser, you can save data in the form of key-value pairs (including arrays) in either LocalStorage or SessionStorage.
As the name suggests, SessionStorage remains only for the current session, and once the browser tab is closed that session's SessionStorage variables are deleted. With LocalStorage, they persist. In both cases, they are accessible only while on the site - only that website can access them, or you can access them through the browser's developer tools (hit F-12 on the keyboard and they should open up).
In my particular browser, they are under the Application tab of the dev tools.
This guide tells you how to use these two storage forms, and you could theoretically use either of them to log to an array or to different variables, or even as a JSON object that is stringified. https://medium.com/@nixonaugustine5/localstorage-and-sessionstorage-in-angular-app-65cda19283a0
This isn't a typical use of LocalStorage or SessionStorage, but it could work if that's what you want to use. You would have to copy/paste out of the browser tools if you wanted to use the log in some other application, though.