Logging Queries to Console
Reported by Paul Mucur | November 9th, 2007 @ 09:17 AM
There does not seem to be an easy way to set DataMapper to log the SQL queries it is performing to the console. This would be particularly useful when using it in conjunction with Merb via the merb_datamapper gem (so perhaps this falls into their purview).
Specifically, it would be nice to replicate the technique described by Jamis Buck in Watching ActiveRecord Do Its Thing which involves the following simple method call:
ActiveRecord::Base.logger = Logger.new(STDOUT)
The closest I managed to get with DataMapper 0.2.3 (and merb_datamapper 0.4.3) was to manually set the logger on line 209 of lib/data_mapper/database.rb but, while it logged some messages to the console, it returned the same information for two different queries:
>> Order[1]
D, [2007-11-09T15:01:23.847022 # 12329] DEBUG -- : host=localhost user=root dbname=some_program_development
D, [2007-11-09T15:01:23.851273 # 12329] DEBUG -- : SET NAMES UTF8
D, [2007-11-09T15:01:23.851955 # 12329] DEBUG -- : SELECT `id`, `reference`, `pack_quantity` FROM `orders` WHERE (`id` = ?)
D, [2007-11-09T15:01:23.852794 # 12329] DEBUG -- : SELECT `id`, `description` FROM `orders` WHERE (`id` IN ?)
=> #<Order:0x174da14 @new_record=false, @pack_quantity=2, @description="An order", @reference="2303", @id=1>
>> Order.all
D, [2007-11-09T15:06:02.721247 # 12329] DEBUG -- : SELECT `id`, `reference`, `pack_quantity` FROM `orders`
D, [2007-11-09T15:06:02.722163 # 12329] DEBUG -- : SELECT `id`, `description` FROM `orders` WHERE (`id` IN ?)
Comments and changes to this ticket
-
Sam Smoot December 10th, 2007 @ 02:07 PM
- State changed from new to open
Added in r572. Set your log_stream to STDOUT. ie:
development: adapter: mysql database: data_mapper_1 username: root log_stream: STDOUT log_level: 0
-
Sam Smoot December 10th, 2007 @ 02:08 PM
- State changed from open to resolved
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »