如何使用Firebase Hosting为已部署的Angular Web应用记录错误 [英] How to log errors with Firebase Hosting for a deployed Angular web app

查看:75
本文介绍了如何使用Firebase Hosting为已部署的Angular Web应用记录错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular单页Web应用程序,该应用程序将Firestore用作数据库,并将部署到Firebase Hosting.除非您正在开发Android或iOS移动应用程序,否则似乎没有内置的方法可以将错误记录到服务器或获取运行时分析.我希望能够查看Web日志文件并查找有关错误或滥用的信息,并查看其他典型的实时使用数据.

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.

例如,如果数据库代码引发错误或Web API调用返回意外值,而我捕获到该错误.在Chrome中进行开发和测试时,我可以console.log问题,但是对于生产网站呢?在Firebase上托管时,在SPA中记录日志的最佳做法是什么?是将记录手动添加到数据库的唯一选择,还是我不熟悉的另一种写服务器日志文件的方式?感谢您提供有关使用Firebase托管Angular Web应用程序记录最佳实践的建议.

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.

推荐答案

https://firebase.google.com/docs/functions/writing-and-viewing-logs

请看看这个.

您的console.log错误似乎足以解决问题

It seems that your console.log errors is enough for firebase

写井日志附带某些针对Firebase的成本和配额策略. 您可以创建一个cloud函数,仅用于编写您在斜角产生的日志.

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.

您可以从有角项目中调用一个api服务,该服务会写入应用程序中唯一的云函数,然后您可以在firebase函数下的日志视图中看到它们.

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.

这篇关于如何使用Firebase Hosting为已部署的Angular Web应用记录错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆