Dependenciesのログ
クラスやモジュールが定義されるタイミングを知りたくてコードを追っていたところ、Rails2.3.2のCHANGELOGに以下のような記述があることに気がつきました。
* Add debugging logging to Dependencies. Currently can be enabled with Dependencies.log_activity = true; adding to Initializer and documenting is forthcoming. [Nicholas Seckar]
RAILS_ROOT/config/environment.rbで以下のように設定すると、
ActiveSupport::Dependencies.logger = Logger.new(STDOUT) ActiveSupport::Dependencies.log_activity = true
以下のように、ロードまわりがロギングされます。
Processing HogesController#index (for ::ffff:192.168.181.1 at 2009-07-25 20:24:45) [GET] Hoge Load (1.5ms) SELECT * FROM "hoges" Rendering template within layouts/hoges Rendering hoges/index Completed in 22ms (View: 11, DB: 2) | 200 OK [http://192.168.181.3/hoges] Dependencies: called new_constants_in(Object) Dependencies: New constants: Dependencies: called new_constants_in(Object) Dependencies: New constants: Dependencies: called load_missing_constant(Object, "HogesController") Dependencies: called require_or_load("/home/masayuki/work/rails/generator/test1/app/controllers/hoges_controller.rb", nil) ...(省略)... Dependencies: called clear() Dependencies: removing constant ApplicationHelper Dependencies: removing constant HogesHelper Dependencies: removing constant ApplicationController Dependencies: removing constant HogesController Dependencies: removing constant Hoge Processing HogesController#new (for ::ffff:192.168.181.1 at 2009-07-25 20:24:47) [GET] Rendering template within layouts/hoges Rendering hoges/new Completed in 20ms (View: 8, DB: 0) | 200 OK [http://192.168.181.3/hoges/new]