简体   繁体   中英

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.

My code is written with 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?

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?

I am writing mobile web apps.

Yes. You can just override console.log function. Simple example:

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

And to access all parameters given to function you can use arguments object .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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