SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Saturday, April 4, 2009

Rails Logging tips

Rails Logging Tips


This article is an reference article,all credits goes to http://mikenaberezny.com/2007/02/24/rails-logging-tips/
Its possible to get the logs of active record & action controller in ruby script/console

Usually while working in rails application we will be checking the log files to view how the sql query executed & how the request from controller has sent.But its possible to view the logs in ruby script/console mode itself.
Enter into console mode
:~/Myworks/Myrails/dpm_devel$ ruby script/console 
Loading development environment (Rails 2.2.2)

Before enabling the log
 User.all
=> [<User id: 1, patientid: "120022009", firstname: "Gen", >]

Now type

ActiveRecord::Base.logger=Logger.new(STDOUT)



User.all
SQL (0.1ms) SET NAMES 'utf8'
SQL (1.1ms) SET SQL_AUTO_IS_NULL=0
User Load (0.1ms) SELECT * FROM `users`
User Columns (0.7ms) SHOW FIELDS FROM `users`
=> [<User id: 1, patientid: "120022009", firstname: "Gen", >]


you can also redirect ActionController’s log output to the console when using script/console:

ActionController::Base.logger = Logger.new(STDOUT)



You can then observe ActionController activities when using using using the app object on the console, such as app.get ‘/’. For a brief tutorial on using app, see this post on Mike Clark’s weblog.