I'm using Rails 4.0.4 with Ruby 2.1 and Thin 1.6.2 on Ubuntu 14.04 through my terminal "Terminator" and my shell "Fish Shell".
When I'm launching my Rails server in development mode I don't have the SQL queries in my logs only the JS and HTML files are loaded.
I'm searching for something like that:
User Load (3.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 ORDER BY "users"."id" ASC LIMIT 1
(2.0ms) SELECT COUNT(*) FROM "users" WHERE (driver_register_state_cd = -2)
The DISPLAY command must be placed immediately after the query statement on which you want it to take effect. For example: SELECT pno, pname FROM part WHERE color='BLUE'; DISPLAY; When the system encounters this DISPLAY command, it displays the Result window containing the part number and name for all blue parts.
One of the best tools in a rails developers arsenal is the rails console, being extremely useful for brainstorming, debugging, and testing. Having it log active record queries directly to the console can improve readability and convenience over looking through the development logs to see what SQL queries have been run.
To write in the current log use the logger. (debug|info|warn|error|fatal|unknown) method from within a controller, model, or mailer: logger. debug "Person attributes hash: #{@person.
Rails uses six different log levels: debug, info, warn, error, fatal, and unknown. Each level defines how much information your application will log: Debug: diagnostic information for developers and system administrators, including database calls or inspecting object attributes.
the rails console never writes to the log file, but you can achieve it quite easily, for example, if you execute following after starting the rails console
ActiveRecord::Base.logger = Logger.new STDOUT
rails will log all SQL statements to stdout, thus display them in your terminal. and since Logger.new accepts any stream as first argument, you could just let it write to the rails development.log:
ActiveRecord::Base.logger = Logger.new File.open('log/development.log', 'a')
Set config.log_level
in config/environments/development.rb to :debug
and restart your local server, console:
config.log_level = :debug
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With