admin管理员组

文章数量:1405600

I maintain logs for my backend node js using log4js and it works fine. But I want to do the same for my front end, But I couldn't find a proper package to do that and also in some blogs I came to know that we cannot maintain files in client-side.

So How do I maintain logs for the react js front end?

Note: I want to maintain logs for both info and error, just like this package

I maintain logs for my backend node js using log4js and it works fine. But I want to do the same for my front end, But I couldn't find a proper package to do that and also in some blogs I came to know that we cannot maintain files in client-side.

So How do I maintain logs for the react js front end?

Note: I want to maintain logs for both info and error, just like this package https://www.npmjs./package/log4js

Share Improve this question asked Jul 10, 2020 at 21:46 Rittesh P.VRittesh P.V 4233 gold badges10 silver badges21 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

There are many ways to do this. However, assuming you want to centralize all of your applications logs in one place, then you must call an endpoint that your application exposes and pass the related log data to that endpoint.

  1. Create an endpoint that your app can HTTP POST log data to. This endpoint will then invoke your log4js logger
  2. Have the client request that endpoint whenever it needs to log data, and send the associated data in the request

One way to log the front end with third party packages is to use sentry io. Either the cloud or self hosted versions act as a centralized place for log management. Since it is started as a separate service, even if your backend goes down, it is still possible to trace your frontend logs.

本文标签: javascriptHow to maintain logs for front end in react jsStack Overflow