le0pard/mongodb_logger

Is there a way to get access to the url of the current mongodb record from inside the controller?

ericmnel opened this issue · 5 comments

I'd like to save the url of the mongo log collection each time I hit a particular error condition, is there a way to get access to the _id to generate a url with? Or is the actual log not generated until after you exit the controller action?

Record to log saved after exit the controller action. What exactly problem you want to solve? Notificate something about error?

I'm keeping a separate database of unique error conditions (if I have seen the error string before I just update the timestamp on the record, otherwise I save a new record) because the error logs were getting lost in the huge volume of normal logs. If I added the url to the mongo record to my new database, I would have not only a list of all outstanding issues, but a click link to the context that the error occurred in with all the other logs for that situation as well.

I suppose that the best thing might be for me to save the error logs in a session variable, and update them all when the mongo log is saved.

If I added the url to the mongo record to my new database, I would have not only a list of all outstanding issues, but a click link to the context that the error occurred in with all the other logs for that situation as well.

Ok, I understand. How about some callback? I can add in logger callback option, which will call some code on error. For example:

MongodbLogger.configure do |config|
  config.on_error do |mongo_record|
    # do something with this record
  end
end

That would be fantastic, thanks!

Ok, I added such functionality:

MongodbLogger::Base.configure do |config|
  config.on_log_exception do |mongo_record|
    # do something with this data, for example - send email (better - by background job)
  end
end

But here little problem - we have all data, except "_id". This is because we do insert without waiting response from MongoDB for maximum speed. I think this should help you. I already release version 0.2.8 with this functionality.