Quantcast

Log Native SQL

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Log Native SQL

Lauro Becker
Hi,

How can I configure Log4J to log SQL statements from groovy.sql.Sql class?

If possible, I'd like to use the same flag used to log Hibernate statements (logSql = true in DataSource.groovy), to turn logging on/off.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Native SQL

jstell
Hi Lauro

There's nothing as simple as a config flag for turning on JDBC SQL logging, but you might take a look at the p6spy plugin : http://www.grails.org/p6spy+plugin


Jason

On Mon, Jan 16, 2012 at 9:42 AM, Lauro Becker <[hidden email]> wrote:
Hi,

How can I configure Log4J to log SQL statements from groovy.sql.Sql class?

If possible, I'd like to use the same flag used to log Hibernate statements (logSql = true in DataSource.groovy), to turn logging on/off.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Native SQL

Lauro Becker
Hi Jason

Don't you know if is possible log just by adding something like log4j = { debug 'org.hibernate.SQL'} in Config?

Anyway, I'll test p6spy.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/16 Jason Stell <[hidden email]>
Hi Lauro

There's nothing as simple as a config flag for turning on JDBC SQL logging, but you might take a look at the p6spy plugin : http://www.grails.org/p6spy+plugin


Jason


On Mon, Jan 16, 2012 at 9:42 AM, Lauro Becker <[hidden email]> wrote:
Hi,

How can I configure Log4J to log SQL statements from groovy.sql.Sql class?

If possible, I'd like to use the same flag used to log Hibernate statements (logSql = true in DataSource.groovy), to turn logging on/off.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Native SQL

Jason Davis
I was looking for this once too. I don't think your above suggestion
would work as groovy Sql object doesnt (normally?) use hibernate.
I would be interested in a solution too. Sometimes its nice to see
exactly how values for prepared statements are substituted.

On Mon, Jan 16, 2012 at 8:58 AM, Lauro Becker <[hidden email]> wrote:

> Hi Jason
>
> Don't you know if is possible log just by adding something like log4j =
> { debug 'org.hibernate.SQL'} in Config?
>
> Anyway, I'll test p6spy.
>
> Thanks!
>
> Lauro L. V. Becker
> ---------------------------
> Blog: http://laurobecker.wordpress.com
>
>
> 2012/1/16 Jason Stell <[hidden email]>
>>
>> Hi Lauro
>>
>> There's nothing as simple as a config flag for turning on JDBC SQL
>> logging, but you might take a look at the p6spy plugin
>> : http://www.grails.org/p6spy+plugin
>>
>>
>> Jason
>>
>>
>> On Mon, Jan 16, 2012 at 9:42 AM, Lauro Becker <[hidden email]>
>> wrote:
>>>
>>> Hi,
>>>
>>> How can I configure Log4J to log SQL statements from groovy.sql.Sql
>>> class?
>>>
>>> If possible, I'd like to use the same flag used to log Hibernate
>>> statements (logSql = true in DataSource.groovy), to turn logging on/off.
>>>
>>> Thanks!
>>>
>>> Lauro L. V. Becker
>>> ---------------------------
>>> Blog: http://laurobecker.wordpress.com
>>
>>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Native SQL

Lauro Becker
Indeed.

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/16 Jason Davis <[hidden email]>
I was looking for this once too. I don't think your above suggestion
would work as groovy Sql object doesnt (normally?) use hibernate.
I would be interested in a solution too. Sometimes its nice to see
exactly how values for prepared statements are substituted.

On Mon, Jan 16, 2012 at 8:58 AM, Lauro Becker <[hidden email]> wrote:
> Hi Jason
>
> Don't you know if is possible log just by adding something like log4j =
> { debug 'org.hibernate.SQL'} in Config?
>
> Anyway, I'll test p6spy.
>
> Thanks!
>
> Lauro L. V. Becker
> ---------------------------
> Blog: http://laurobecker.wordpress.com
>
>
> 2012/1/16 Jason Stell <[hidden email]>
>>
>> Hi Lauro
>>
>> There's nothing as simple as a config flag for turning on JDBC SQL
>> logging, but you might take a look at the p6spy plugin
>> : http://www.grails.org/p6spy+plugin
>>
>>
>> Jason
>>
>>
>> On Mon, Jan 16, 2012 at 9:42 AM, Lauro Becker <[hidden email]>
>> wrote:
>>>
>>> Hi,
>>>
>>> How can I configure Log4J to log SQL statements from groovy.sql.Sql
>>> class?
>>>
>>> If possible, I'd like to use the same flag used to log Hibernate
>>> statements (logSql = true in DataSource.groovy), to turn logging on/off.
>>>
>>> Thanks!
>>>
>>> Lauro L. V. Becker
>>> ---------------------------
>>> Blog: http://laurobecker.wordpress.com
>>
>>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Native SQL

jstell
In reply to this post by Lauro Becker
Hi Lauro

It looks like groovy.sql.Sql does do some logging via java.util.logging (not log4j)
You could try enabling this by putting something like the following in your Bootstrap.groovy:

... but I haven't tested this.
You may also need to tweak your logging.properties file so the ConsoleHandler outputs FINE messages. 

Cross-posting this to the groovy ML for better info :)

Jason

On Mon, Jan 16, 2012 at 9:58 AM, Lauro Becker <[hidden email]> wrote:
Hi Jason

Don't you know if is possible log just by adding something like log4j = { debug 'org.hibernate.SQL'} in Config?

Anyway, I'll test p6spy.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/16 Jason Stell <[hidden email]>
Hi Lauro

There's nothing as simple as a config flag for turning on JDBC SQL logging, but you might take a look at the p6spy plugin : http://www.grails.org/p6spy+plugin


Jason


On Mon, Jan 16, 2012 at 9:42 AM, Lauro Becker <[hidden email]> wrote:
Hi,

How can I configure Log4J to log SQL statements from groovy.sql.Sql class?

If possible, I'd like to use the same flag used to log Hibernate statements (logSql = true in DataSource.groovy), to turn logging on/off.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Native SQL

Lauro Becker
Wow! It is almost easier using p6spy. :P

I need to write these logs to the same file as log4j does, so I don't know if it helps. I guess I can integrate both with a Handler.

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/16 Jason Stell <[hidden email]>
Hi Lauro

It looks like groovy.sql.Sql does do some logging via java.util.logging (not log4j)
You could try enabling this by putting something like the following in your Bootstrap.groovy:

... but I haven't tested this.
You may also need to tweak your logging.properties file so the ConsoleHandler outputs FINE messages. 

Cross-posting this to the groovy ML for better info :)

Jason


On Mon, Jan 16, 2012 at 9:58 AM, Lauro Becker <[hidden email]> wrote:
Hi Jason

Don't you know if is possible log just by adding something like log4j = { debug 'org.hibernate.SQL'} in Config?

Anyway, I'll test p6spy.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/16 Jason Stell <[hidden email]>
Hi Lauro

There's nothing as simple as a config flag for turning on JDBC SQL logging, but you might take a look at the p6spy plugin : http://www.grails.org/p6spy+plugin


Jason


On Mon, Jan 16, 2012 at 9:42 AM, Lauro Becker <[hidden email]> wrote:
Hi,

How can I configure Log4J to log SQL statements from groovy.sql.Sql class?

If possible, I'd like to use the same flag used to log Hibernate statements (logSql = true in DataSource.groovy), to turn logging on/off.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Native SQL

Lauro Becker
Hi Jason,

Following your suggestion about java.util.logging, I've created a very simple solution.

Add the following lines to your Bootstrap, for example:

Logger sqlLogger = Logger.getLogger(Sql.class.getName())
sqlLogger.addHandler(new SqlHandler());
sqlLogger.setLevel(Level.FINE)

Add SqlHandler to your project and update your Config for logging 'groovy.sql'. For example: info 'groovy.sql'.

Cheers,

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/16 Lauro Becker <[hidden email]>
Wow! It is almost easier using p6spy. :P

I need to write these logs to the same file as log4j does, so I don't know if it helps. I guess I can integrate both with a Handler.


Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/16 Jason Stell <[hidden email]>
Hi Lauro

It looks like groovy.sql.Sql does do some logging via java.util.logging (not log4j)
You could try enabling this by putting something like the following in your Bootstrap.groovy:

... but I haven't tested this.
You may also need to tweak your logging.properties file so the ConsoleHandler outputs FINE messages. 

Cross-posting this to the groovy ML for better info :)

Jason


On Mon, Jan 16, 2012 at 9:58 AM, Lauro Becker <[hidden email]> wrote:
Hi Jason

Don't you know if is possible log just by adding something like log4j = { debug 'org.hibernate.SQL'} in Config?

Anyway, I'll test p6spy.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/16 Jason Stell <[hidden email]>
Hi Lauro

There's nothing as simple as a config flag for turning on JDBC SQL logging, but you might take a look at the p6spy plugin : http://www.grails.org/p6spy+plugin


Jason


On Mon, Jan 16, 2012 at 9:42 AM, Lauro Becker <[hidden email]> wrote:
Hi,

How can I configure Log4J to log SQL statements from groovy.sql.Sql class?

If possible, I'd like to use the same flag used to log Hibernate statements (logSql = true in DataSource.groovy), to turn logging on/off.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com





Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Native SQL

jstell
Clever!

Jason

On Tue, Jan 17, 2012 at 12:19 PM, Lauro Becker <[hidden email]> wrote:
Hi Jason,

Following your suggestion about java.util.logging, I've created a very simple solution.

Add the following lines to your Bootstrap, for example:

Logger sqlLogger = Logger.getLogger(Sql.class.getName())
sqlLogger.addHandler(new SqlHandler());
sqlLogger.setLevel(Level.FINE)

Add SqlHandler to your project and update your Config for logging 'groovy.sql'. For example: info 'groovy.sql'.

Cheers,

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/16 Lauro Becker <[hidden email]>
Wow! It is almost easier using p6spy. :P

I need to write these logs to the same file as log4j does, so I don't know if it helps. I guess I can integrate both with a Handler.


Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/16 Jason Stell <[hidden email]>
Hi Lauro

It looks like groovy.sql.Sql does do some logging via java.util.logging (not log4j)
You could try enabling this by putting something like the following in your Bootstrap.groovy:

... but I haven't tested this.
You may also need to tweak your logging.properties file so the ConsoleHandler outputs FINE messages. 

Cross-posting this to the groovy ML for better info :)

Jason


On Mon, Jan 16, 2012 at 9:58 AM, Lauro Becker <[hidden email]> wrote:
Hi Jason

Don't you know if is possible log just by adding something like log4j = { debug 'org.hibernate.SQL'} in Config?

Anyway, I'll test p6spy.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com


2012/1/16 Jason Stell <[hidden email]>
Hi Lauro

There's nothing as simple as a config flag for turning on JDBC SQL logging, but you might take a look at the p6spy plugin : http://www.grails.org/p6spy+plugin


Jason


On Mon, Jan 16, 2012 at 9:42 AM, Lauro Becker <[hidden email]> wrote:
Hi,

How can I configure Log4J to log SQL statements from groovy.sql.Sql class?

If possible, I'd like to use the same flag used to log Hibernate statements (logSql = true in DataSource.groovy), to turn logging on/off.

Thanks!

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com






Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Native SQL

Tomi N/A
Or you could do it this way:

http://stackoverflow.com/questions/2568507/how-to-log-sql-statements-in-grails/2568617#2568617

Cheers, Tomislav

2012/1/17 Jason Stell <[hidden email]>:

> Clever!
>
> Jason
>
>
> On Tue, Jan 17, 2012 at 12:19 PM, Lauro Becker <[hidden email]>
> wrote:
>>
>> Hi Jason,
>>
>> Following your suggestion about java.util.logging, I've created a very
>> simple solution.
>>
>> Add the following lines to your Bootstrap, for example:
>>
>>> Logger sqlLogger = Logger.getLogger(Sql.class.getName())
>>> sqlLogger.addHandler(new SqlHandler());
>>> sqlLogger.setLevel(Level.FINE)
>>
>>
>> Add SqlHandler to your project and update your Config for logging
>> 'groovy.sql'. For example: info 'groovy.sql'.
>>
>> Cheers,
>>
>> Lauro L. V. Becker
>> ---------------------------
>> Blog: http://laurobecker.wordpress.com
>>
>>
>> 2012/1/16 Lauro Becker <[hidden email]>
>>>
>>> Wow! It is almost easier using p6spy. :P
>>>
>>> I need to write these logs to the same file as log4j does, so I don't
>>> know if it helps. I guess I can integrate both with a Handler.
>>>
>>>
>>> Lauro L. V. Becker
>>> ---------------------------
>>> Blog: http://laurobecker.wordpress.com
>>>
>>>
>>> 2012/1/16 Jason Stell <[hidden email]>
>>>>
>>>> Hi Lauro
>>>>
>>>> It looks like groovy.sql.Sql does do some logging via java.util.logging
>>>> (not log4j)
>>>> You could try enabling this by putting something like the following in
>>>> your Bootstrap.groovy:
>>>>
>>>>
>>>> java.util.logging.Logger.getLogger(groovy.sql.Sql.class.getName()).setLevel(java.util.logging.Level.FINE)
>>>>
>>>>
>>>> ... but I haven't tested this.
>>>> You may also need to tweak your logging.properties file so the
>>>> ConsoleHandler outputs FINE messages.
>>>>
>>>> Cross-posting this to the groovy ML for better info :)
>>>>
>>>> Jason
>>>>
>>>>
>>>> On Mon, Jan 16, 2012 at 9:58 AM, Lauro Becker <[hidden email]>
>>>> wrote:
>>>>>
>>>>> Hi Jason
>>>>>
>>>>> Don't you know if is possible log just by adding something like log4j =
>>>>> { debug 'org.hibernate.SQL'} in Config?
>>>>>
>>>>> Anyway, I'll test p6spy.
>>>>>
>>>>> Thanks!
>>>>>
>>>>> Lauro L. V. Becker
>>>>> ---------------------------
>>>>> Blog: http://laurobecker.wordpress.com
>>>>>
>>>>>
>>>>> 2012/1/16 Jason Stell <[hidden email]>
>>>>>>
>>>>>> Hi Lauro
>>>>>>
>>>>>> There's nothing as simple as a config flag for turning on JDBC SQL
>>>>>> logging, but you might take a look at the p6spy plugin
>>>>>> : http://www.grails.org/p6spy+plugin
>>>>>>
>>>>>>
>>>>>> Jason
>>>>>>
>>>>>>
>>>>>> On Mon, Jan 16, 2012 at 9:42 AM, Lauro Becker <[hidden email]>
>>>>>> wrote:
>>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> How can I configure Log4J to log SQL statements from groovy.sql.Sql
>>>>>>> class?
>>>>>>>
>>>>>>> If possible, I'd like to use the same flag used to log Hibernate
>>>>>>> statements (logSql = true in DataSource.groovy), to turn logging on/off.
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>> Lauro L. V. Becker
>>>>>>> ---------------------------
>>>>>>> Blog: http://laurobecker.wordpress.com
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Native SQL

Jason Davis
yeah, that doesnt work with the groovy Sql object.

On Wed, Jan 18, 2012 at 3:15 AM, Tomi N/A <[hidden email]> wrote:

> Or you could do it this way:
>
> http://stackoverflow.com/questions/2568507/how-to-log-sql-statements-in-grails/2568617#2568617
>
> Cheers, Tomislav
>
> 2012/1/17 Jason Stell <[hidden email]>:
>> Clever!
>>
>> Jason
>>
>>
>> On Tue, Jan 17, 2012 at 12:19 PM, Lauro Becker <[hidden email]>
>> wrote:
>>>
>>> Hi Jason,
>>>
>>> Following your suggestion about java.util.logging, I've created a very
>>> simple solution.
>>>
>>> Add the following lines to your Bootstrap, for example:
>>>
>>>> Logger sqlLogger = Logger.getLogger(Sql.class.getName())
>>>> sqlLogger.addHandler(new SqlHandler());
>>>> sqlLogger.setLevel(Level.FINE)
>>>
>>>
>>> Add SqlHandler to your project and update your Config for logging
>>> 'groovy.sql'. For example: info 'groovy.sql'.
>>>
>>> Cheers,
>>>
>>> Lauro L. V. Becker
>>> ---------------------------
>>> Blog: http://laurobecker.wordpress.com
>>>
>>>
>>> 2012/1/16 Lauro Becker <[hidden email]>
>>>>
>>>> Wow! It is almost easier using p6spy. :P
>>>>
>>>> I need to write these logs to the same file as log4j does, so I don't
>>>> know if it helps. I guess I can integrate both with a Handler.
>>>>
>>>>
>>>> Lauro L. V. Becker
>>>> ---------------------------
>>>> Blog: http://laurobecker.wordpress.com
>>>>
>>>>
>>>> 2012/1/16 Jason Stell <[hidden email]>
>>>>>
>>>>> Hi Lauro
>>>>>
>>>>> It looks like groovy.sql.Sql does do some logging via java.util.logging
>>>>> (not log4j)
>>>>> You could try enabling this by putting something like the following in
>>>>> your Bootstrap.groovy:
>>>>>
>>>>>
>>>>> java.util.logging.Logger.getLogger(groovy.sql.Sql.class.getName()).setLevel(java.util.logging.Level.FINE)
>>>>>
>>>>>
>>>>> ... but I haven't tested this.
>>>>> You may also need to tweak your logging.properties file so the
>>>>> ConsoleHandler outputs FINE messages.
>>>>>
>>>>> Cross-posting this to the groovy ML for better info :)
>>>>>
>>>>> Jason
>>>>>
>>>>>
>>>>> On Mon, Jan 16, 2012 at 9:58 AM, Lauro Becker <[hidden email]>
>>>>> wrote:
>>>>>>
>>>>>> Hi Jason
>>>>>>
>>>>>> Don't you know if is possible log just by adding something like log4j =
>>>>>> { debug 'org.hibernate.SQL'} in Config?
>>>>>>
>>>>>> Anyway, I'll test p6spy.
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>> Lauro L. V. Becker
>>>>>> ---------------------------
>>>>>> Blog: http://laurobecker.wordpress.com
>>>>>>
>>>>>>
>>>>>> 2012/1/16 Jason Stell <[hidden email]>
>>>>>>>
>>>>>>> Hi Lauro
>>>>>>>
>>>>>>> There's nothing as simple as a config flag for turning on JDBC SQL
>>>>>>> logging, but you might take a look at the p6spy plugin
>>>>>>> : http://www.grails.org/p6spy+plugin
>>>>>>>
>>>>>>>
>>>>>>> Jason
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Jan 16, 2012 at 9:42 AM, Lauro Becker <[hidden email]>
>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> How can I configure Log4J to log SQL statements from groovy.sql.Sql
>>>>>>>> class?
>>>>>>>>
>>>>>>>> If possible, I'd like to use the same flag used to log Hibernate
>>>>>>>> statements (logSql = true in DataSource.groovy), to turn logging on/off.
>>>>>>>>
>>>>>>>> Thanks!
>>>>>>>>
>>>>>>>> Lauro L. V. Becker
>>>>>>>> ---------------------------
>>>>>>>> Blog: http://laurobecker.wordpress.com
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Log Native SQL

burtbeckwith
In reply to this post by Lauro Becker
I was struggling with this issue today and found a simpler solution. I wrote it up here: http://burtbeckwith.com/blog/?p=1654

Burt

Lauro Becker wrote
Hi Jason,

Following your suggestion about java.util.logging, I've created a very
simple solution.

Add the following lines to your Bootstrap, for example:

Logger sqlLogger = Logger.getLogger(Sql.class.getName())
> sqlLogger.addHandler(new SqlHandler());
> sqlLogger.setLevel(Level.FINE)


Add SqlHandler<https://github.com/laurobecker/grails-dao-artefacts/blob/master/src/groovy/br/com/organicadigital/daoartefacts/SqlHandler.groovy>to
your project and update your Config for logging 'groovy.sql'. For
example: *info 'groovy.sql'*.

Cheers,

Lauro L. V. Becker
---------------------------
Blog: http://laurobecker.wordpress.com
Loading...