简体   繁体   中英

Logging every API request in Ember-Data

I'm still a bit new to Ember. I'm using Ember 1.13 with Ember Data and the DS.RESTAdapter. For debugging purposes, as well as educational (such as getting a feel for how Ember Data works with various options such as the shouldReload* functions), I want to log every API request with mainly the URL called and optionally how it was called (eg, from a store.findAll() or store.queryRecord() , etc.). Is there a single place (my guess is somewhere in adapter:application ?) where I can put a single console.log('URL called: ', url, ', from: ', callingFunction); that handles all of this?

If you use the JSONAPIAdapter or the RESTAdapter just override ajax() on the adapter to log the URI:

ajax(url, type, options) {
  console.log(url);
  return this._super(...arguments);
}

There is no easy way to get the caller function. Analyse the callstack, if its just for debugging purposes! But, maybe just use the Browser log XMLHttpRequest option if its for debugging?!

If you want to know how it works, checkout the code. The adapter and the store is where you can look for knowledge.

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