jeudi 3 décembre 2015

How can I save the browser console logs to my DB without overriding console.log

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?

Aucun commentaire:

Enregistrer un commentaire