How to turn on SQL DEBUG logging?

1,298 views
Skip to first unread message

Ravi Mendis

unread,
Feb 28, 2010, 10:14:11 PM2/28/10
to Squeryl
I've got a fantastic little concurrent application in which Scala
Actors access a database with Squeryl.
But i would like to see the SQL generated.

How does one turn on SQL logging?

Maxime Lévesque

unread,
Feb 28, 2010, 10:51:16 PM2/28/10
to squ...@googlegroups.com

 Hi Ravi, nice to hear that Squeryl is doing usefull work ! ;-)

There are two ways of seeing the generated SQL :

1) The org.squery.Query[T].statement: String  method, ex :

 val q = aTable.where(t => t.aField === x)

 println(q.statement)


2)  The org.squeryl.Session.setLogger(String=>Unit) method, ex :

  Session.currentSession.setLogger(msg => println(msg))

With this method you will see pretty much every statement passed to jdbc,
and a dump of result sets of the seesion.

  Cheers !

  Max

Ravi Mendis

unread,
Mar 18, 2010, 7:55:43 PM3/18/10
to Squeryl
Hi Maxime,

I'm trying out the new SessionFactory and transaction {} notation -
and i have to say i'm liking it ;)
It actually makes my code less verbose, but there's one thing i've not
figured out...

When using:

SessionFactory.concreteFactory = Option(() => Session.create(
java.sql.DriverManager.getConnection("jdbc:postgresql://
localhost:5432/sque ryl", "squeryl", "squeryl"),
new PostgreSqlAdapter
))

What is the new way of setting a logger for SQL?

Thanks,
Ravi

On Mar 1, 2:51 pm, Maxime Lévesque <maxime.leves...@gmail.com> wrote:
>  Hi Ravi, nice to hear that Squeryl is doing usefull work ! ;-)
>
> There are two ways of seeing the generated SQL :
>
> 1) The org.squery.Query[T].statement: String  method, ex :
>
>  val q = aTable.where(t => t.aField === x)
>
>  println(q.statement)
>
> 2)  The org.squeryl.Session.setLogger(String=>Unit) method, ex :
>
>   Session.currentSession.setLogger(msg => println(msg))
>
> With this method you will see pretty much every statement passed to jdbc,
> and a dump of result sets of the seesion.
>
>   Cheers !
>
>   Max
>

Max

unread,
Mar 18, 2010, 8:15:36 PM3/18/10
to Squeryl

Session.currentSession.setLogger is still available,

you can call it at any time

Session.currentSession.setLogger(msg => {...do something with msg} )

provided that there is a Session bound to the current thread, wich is
the case
if you are inside a transaction.


Cheers !

Ravi Mendis

unread,
Mar 18, 2010, 10:34:29 PM3/18/10
to Squeryl
I suppose the question is really: Is there (going to be) a way to set
it on the factory?

Maxime Lévesque

unread,
Mar 19, 2010, 7:12:43 AM3/19/10
to squ...@googlegroups.com

This could be implemented with less than 5 lines of code.
I once thought about it and my hesitation was that setting it on the factory
would have to turn on logging for the whole VM (as opposed to
the current thread). Your log file would become very big, very fast.
On the other hand it's nice to have control, and it would only grow the
API by one line, so that puts me 50/50 on this one,
so if one person tells me it would be usefull, I'll add it in there ! ;-)

 Cheers

To unsubscribe from this group, send email to squeryl+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Reply all
Reply to author
Forward
0 new messages