Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Logging #62

Closed
crisward opened this issue Jul 21, 2017 · 1 comment · Fixed by #134
Closed

Query Logging #62

crisward opened this issue Jul 21, 2017 · 1 comment · Fixed by #134

Comments

@crisward
Copy link
Contributor

I realise it's possible to do this with access to the db. But it would be useful, especially when debugging performance to be able to get the raw queries logged.

ie

db = DB.open(ENV["DATABASE_URL"])
db.logger = ->mylogger(String)
db.logging = true
# do some stuff
db.logging = false

def mylogger(sql : String)
  puts "#{Time.new} #{sql}"
end

I could imagine using this to get all the queries used on a single request. Though I'm unsure if this would work with the async nature of how queries are handled. I'll happily give this a go if anyone else thinks this is feasible.

@crisward
Copy link
Contributor Author

In terms of running a log command - does anyone know if there is a better place than this to grab the sql string for each request other than this ? I've chucked a puts @query in there and it seems to work. It doesn't have any arguments inserted, but it's not a bad first step.

https://github.com/crystal-lang/crystal-db/blob/master/src/db/pool_statement.cr#L9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant