I have a very large app that logs a lot of stuff happening in it.
When there's a client error, I want to send a history of X logs to my db.
To do that I first thought of something like that:
var yo = { log: function() { //some logic to save arguments to a queue console.log(arguments); }, error: function() { //some logic to save arguments to a queue //some logic to save queue to db console.error(arguments); } }
and then use
yo.log()instead of
console.log()
The problem with this method is that all errors and logs (in chrome's console) debug link directs to the yo function definition instead of the actual error in the code.
Does anyone know has a better solution to this problem?
Here is a simple example: http://codepen.io/guysopher/pen/xZKMgG
var yo = {
log: function() {
console.log.apply(console, arguments);
}
}
console.log('This shows the right line number!');
yo.log('This shows the wrong line number!');