tomdearman / log4jdbc-log4j2

Automatically exported from code.google.com/p/log4jdbc-log4j2
0 stars 0 forks source link

Log the output from SQL print statements #22

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Call Statement.execute() with SQL: print 'test'
2. Nothing logs.

What is the expected output? What do you see instead?

I wrote a quick Java app to test what the following SQL would output with 
Statement.getWarnings():

print 'test'

For a SQL Server 2012 database it prints:

test

For a Sybase 12.5 database it prints:

test

Please see the attached Java code.  I obfuscated the connection details, 
username and password.

I only have access to a SQL Server and Sybase database... not sure what other 
databases would output.

What version of the product are you using? On what operating system?

log4jdbc-log4j2-jdbc4.1, version 1.16 on Windows 7

Please provide any additional information below.

I am using log4jdbc-log4j2 with Liquibase so I can see more details of what 
happened during a update or rollback.  What I really want to see is the output 
of sql print statements (like the Output screen from a database tool).  I found 
that JDBC Statement.getWarnings() can be used to get SQL output:

http://dba.stackexchange.com/questions/44372/is-there-any-way-to-retrieve-messag
es-in-sql-server-through-jdbc

http://stackoverflow.com/questions/6434338/when-to-call-getwarnings-on-connectio
ns-statements-and-resultsets-with-jdbc

This feature could be activated with a system property similar to 
log4jdbc.statement.warn, defaulted to false.

Original issue reported on code.google.com by steven.d...@gmail.com on 3 Sep 2014 at 5:50

Attachments:

GoogleCodeExporter commented 9 years ago
I had a go at implementing logging of SQL Messages and tested it in our 
Liquibase implementation with SLF4J and JDBC 4.1.  Print statements log 
successfully.

It is just a start on the full implementation. For example, I did not implement 
the Log4J 2 logging method (the method is empty) as I am not familiar with 
Log4J 2.

I also have not implemented logging of SQL Message the JDBC 3 and 4 modules.

Please see the attached Patch for Subversion.

Original comment by steven.d...@gmail.com on 4 Sep 2014 at 12:10

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the proposed patch. Question: if you plan to use a specific logger 
for these messages, why defining the property DumpSqlMessage? This could be 
managed simply by setting the appropriate logger on/off, right?

Original comment by frederic...@gmail.com on 7 Oct 2014 at 4:12

GoogleCodeExporter commented 9 years ago
Actually, I see that SQLWarnings should be logged by the 'resultSetLogger' when 
using SLF4J, and with the Marker 'LOG4JDBC_RESULTSET' when using Log4j2. Have 
you tried using these loggers/markers?

Original comment by frederic...@gmail.com on 31 Jan 2015 at 11:21

GoogleCodeExporter commented 9 years ago

Original comment by frederic...@gmail.com on 31 Jan 2015 at 11:21