问题
I am working on an Angular single page web app which uses Firestore as the database and will be deployed to Firebase Hosting. There seems to be no built-in way to log errors to the server or get run-time analytics unless you are developing an Android or iOS mobile app. I want to be able to view the web log files and find out about errors or abuse and see other typical live usage data.
For example if the database code throws an error or a web API call returns an unexpected value and I catch the error. I can console.log the problem when developing and testing in Chrome, but what about for a production website? What is the best practice for logging within a SPA when hosting on Firebase? Is the only option to manually add records to the database or is there another way I am not familiar with to write to a server log file? Thanks for your advice on logging best practices with Firebase hosting an Angular web app.
回答1:
https://firebase.google.com/docs/functions/writing-and-viewing-logs
Please have a look into this.
It seems that your console.log errors is enough for firebase
EDIT
well writing logs comes with certain cost and quota policy for firebase. You can create a cloud function just to write the logs that you incur in the angular side.
You can call an api service from the angular project that writes into the only cloud function in your app and then you can see those in the logs view under firebase functions.
But please note that it may come under some cost.
来源:https://stackoverflow.com/questions/51212886/how-to-log-errors-with-firebase-hosting-for-a-deployed-angular-web-app