Logging DataMapper SQL Queries in Merb
I have been experimenting with Merb for a while as an alternative to Rails.
Compared to Rails, Merb is a lightweight framework. By default Merb strips away a lot of unnecessary cruft, and in doing so does not include a default Object Relational Mapping (ORM), such as the popular ActiveRecord. Though this doesn’t prevent it from utilizing one, you are given the option of using a variety of frameworks to satisfy your application’s needs. Presently Merb supports ActiveRecord, DataMapper, and Sequel.
Out of the three I decided to experiment with DataMapper, as I was already familiar with ActiveRecord, and wanted to explore something new.
When using the default settings, DataMapper doesn’t log the queries! This makes it extremely difficult to debug an ORM especially when you are new to it.
Enabling Logging
Luckily you can add two keys :log_stream and :log_level to your config/database.yml to enable logging.
:development: &defaults
:adapter: sqlite3
:database: application_development
:log_stream: STDOUT
:log_level: 0
Disabling Logging
Now When going into production mode, you should (if you desire) turn logging off.
:production:
<<: *defaults
:database: application_production
:log_stream: nil
:

