简体   繁体   English

扩展console.log()的javascript Web应用程序的客户端日志记录

[英]Client side logging for javascript web applications that extends console.log()

I have been searching the internet for a clean solution regarding client side logging for a javascript apps and have not come across an obvious choice. 我一直在互联网上寻找关于javascript应用程序的客户端日志记录的干净解决方案,但没有遇到明显的选择。

My code is written with console.log() . 我的代码是用console.log()编写的。 I was hoping to find a javascript plugin that over-rides console.log() , such that i dont need to change my code, and also extends it so I can do things like programatically get the last 10 log lines to show the user? 我希望找到一个可以覆盖console.log()的javascript插件,这样我就不需要更改代码,也可以对其进行扩展,这样我就可以像以编程方式获取最后10条日志行来显示用户了吗?

Should I just over-ride console.log() in my application so that apart from printing to the console, it saves the logs to a global array? 我是否应该在应用程序中重写console.log(),以便除了打印到控制台外,还可以将日志保存到全局数组中?

I am writing mobile web apps. 我正在编写移动Web应用程序。

Yes. 是。 You can just override console.log function. 您可以覆盖console.log函数。 Simple example: 简单的例子:

var logs = [];
console.log = function(value) {
    logs.push(value);
}

And to access all parameters given to function you can use arguments object . 要访问赋予函数的所有参数,可以使用arguments对象

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

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