简体   繁体   English

如何使用ngx-logger获取角度的日志文件?

[英]how can I get a log file in angular using ngx-logger?

How to set logs to file in angular rather that printing logs in console. 如何将日志设置为有角度的文件,而不是在控制台中打印日志。 I'm using ngx-logger. 我正在使用ngx-logger。 Do you have any suggestions? 你有什么建议吗?

It's not possible to write to a file from angular, since it is purely on client side. 由于它完全在客户端,因此无法从角度写入文件。

The possible solution would be to send to the server and write to a file or use any of the cloud provider such as azure/aws existing feature appInsights/cloudwatch to log the errors. 可能的解决方案是发送到服务器并写入文件,或使用任何云提供程序(例如azure / aws现有功能appInsights / cloudwatch)记录错误。

According to https://github.com/A1rPun/ngx-logger there's a function to post the log to the server end. 根据https://github.com/A1rPun/ngx-logger的介绍,具有将日志发布到服务器端的功能。 if there's no function, modify the library and add one. 如果没有功能,请修改库并添加一个。

//Post to an endpoint somewhere on the internets
logToEndpoint(logMessage: any): void {
  this.http.post(url, logMessage);
}

Example payload 有效负载示例

{
  'level': 'info',
  'message': 'Hello log!',
  'app': 'MyApp',
  'timestamp': '1337133371337'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM