How to enable query logger in rom-sql (rom-rb)? - ruby

In rom-sql I want to enable logging, so that I can see all the sql queries that are produced.
How can I achieve that?
Because it uses sequel underneath, I guest it may be somehow possible through sequel logger.

Got it: ROM::SQL::Gateway#use_logger

Related

Output SQL from an ActiveRecord migration without executing it (not rails!)

There's a bunch of questions out there similar to this one that talk about rails plugins as a solution - but I'm not using rails, read on for more
I have a Rakefile in a sinatra project which allows me to rake db:migrate. It'll do my migration perfectly, but I'd like to pass that a flag (or write a new rake task) which does the same thing, but outputs the SQL to STDOUT and doesn't commit the changes to the database. Does anyone know how to do this?
My first thought was to try ActiveRecord logging and see if I could get the SQL out at all, but that doesn't work! Any ideas?
namespace :db do
task :migrate_sql do
require 'logger'
ActiveRecord::Base.logger = Logger.new(STDOUT)
Rake::Task['db:migrate'].invoke
# This does the migration and doesn't output SQL - so no good!
end
end
I think there isn't any easy way to do it, for the following reasons:
up, down, and change are methods which execute other methods; there isn't a global migration query string that gets built and executed
neither the statements methods (add_column, etc) expose their statements as strings; as I understand, they are implemented as connection adapter methods, and for example the mysql adapter has a add_column_sql method, while the postgresql adapter does not, and its sql is a variable inside its add_column method
So, if you really need this functionality, I think your best option is to copy the sql from the log.

Diagnostic Monitor Trace Listener

I would like to know if it is possible to modify the way the Trace is recording trace information ?
Trace.Listeners.Add(new DiagnosticMonitorTraceListener());
Trace.TraceInformation("OnStart");
I would like to be able to use the current WADLogsTable and adding one or more custom columns to the table.
Right now the default table created by the DiagnosticMonitorConfiguration looks like that:
PartitionKey|RowKey|Timestamp|EventTickCount|DeploymentID|Role|RoleInstance|Level|EventID|Pid|TiD|Message|
I would like to add at the end some custom columns like :
PartitionKey|RowKey|Timestamp|EventTickCount|DeploymentID|Role|RoleInstance|Level|EventID|Pid|TiD|Message|Custom1|Custom2
So every time I trace something I am able to add data for those two custom columns
Thanks
I don't think you'll be able to do this. While Windows Azure Diagnostics is quite extensible, you'll not be able to modify schema for trace logging. I would recommend looking into implementing custom diagnostics. You may find this link useful for this: http://convective.wordpress.com/2009/12/08/custom-diagnostics-in-windows-azure/.
As Gaurav mentioned, this is not doable with default implementation of Trace.
I'd recommend using something like Log4Net and implementing a custom Table Storage appender. I've done this on a number of projects and it works wonderfully. It (Log4Net) can also consume regular Trace messages and log them into its storage

How to profile Doctrine MongoDB ODM?

How can I profile Doctrine MongoDB ODM?
I would like to see all queries against database and the time of execution. Is there any way to configure a profiler? I would like to build a plugin that I would use it in ZFDebug toolbar.
The MongoDBODMModule for ZF2 may have some classes you could re-use to handle this problem in ZF1. If you're already using ZF2, then it is just a matter of installing the module and ZendDeveloperTools to have the toolbar.
MongoDB has its own profiler, check http://docs.mongodb.org/manual/tutorial/manage-the-database-profiler/

How do I set Ruby Sequel logging to the DEBUG level?

The default Ruby Sequel behaviour is to log all DB queries at the INFO level (unlike ActiveRecord which logs at the DEBUG level). How do I change this?
Previously, it was fairly simple to do with a proxy logger object, but enough people have asked for this that I implemented it. With the git master branch of Sequel, you can now do:
DB.sql_log_level = :debug
Which will use the debug method instead of the info method when logging queries.

How to log all Doctrine queries to file?

I'm using Doctrine and want to log all generated SQL queries.
I know that I could use $q->getSqlQuery() but I don't want to do that manually each time.
Is there a way to do it automatically?
If you turn logging on all queries shoudl be logged to your application log in the log directory. To do this set logging_enabled to true in your settings.yml.
Take a look at Doctrine Profiler and the source of ZF_Debug & Doctrine.

Resources