Can we get the name of the package from which a SQL query was fired?

22 views
Skip to first unread message

HV139

unread,
Jul 31, 2013, 1:33:10 PM7/31/13
to jdbcdslo...@googlegroups.com


I am using jdbcdslog with log4j logging engine in a webapp. I am able to log SQL queries that are executed. I want to know how to get the name of the package from which the query was fired. So that I can separate out the Log information, and know where a query cam from just by looking at the log, rather than going through the code.

I tried to use the %C parameter in PatternLayout of Log4j to get the package name as mentioned here

But the output I get is

2013-07-30-main--INFO -org.jdbcdslog.StatementLogger:java.sql.Statement.executeQuery: SELECT id, first, last, age FROM Employees;

As you can see, the SQL query is logged, but the class it gave out is org.jdbcdslog.StatementLogger. Which is not what is desired, Since I want the name of the class the query was fired from.

I am using the following setting in Log4j.properties file

log4j.appender.S.layout.ConversionPattern=%d{yyyy-MM-dd}-%t-%x-%-5p-%C:%m%n

As jdbcdslog wraps the connection to the JDBC driver, I am not able to get what I really want. 

I want to know how to get the name of the class where the query was fired from.

Any help is very much appreciated.

Thank you.

Andrey Kolyadenko

unread,
Jul 31, 2013, 1:38:50 PM7/31/13
to jdbcdslo...@googlegroups.com
There is configuration parameter which can help you:

  • jdbcdslog.printStackTrace - jdbcdslog will log calling method stack trace if this parameter set to 'true' value. Please keep in mind that turning on of this parameter can kill performance of application.


--
You received this message because you are subscribed to the Google Groups "jdbcdslog-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jdbcdslog-disc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

HV139

unread,
Jul 31, 2013, 2:11:42 PM7/31/13
to jdbcdslo...@googlegroups.com
Thank you for your reply. Is there a way to get this information runtime as metadata of the query? I want to use this information in creating log packages for a pool of services under a huge web-app. And every service package is full of SQL queries. If I get this information without looking at the stacktrace, and if it can be made usable, then I will be able to make different log files for different service packages, instead of putting them all together in one log file and then postprocessing the stacktrace. Also like you mentioned, it will be an overkill. is there a workaround for this?

Andrey Kolyadenko

unread,
Jul 31, 2013, 2:15:56 PM7/31/13
to jdbcdslo...@googlegroups.com
I think I tried to implement something like that, I tried to extract method + package name from stack trace, but the problem was that it's not clear how many stack levels between jdbcdslog logic and calling logic, depends on different factors number of levels can be different. Unfortunately I didn't find good workaround for this problem.

HV139

unread,
Jul 31, 2013, 2:38:29 PM7/31/13
to jdbcdslo...@googlegroups.com
Oh, but still this is the best Logger I have used till date. I want this functionality in my web-app. I'm going through the loggers code trying to understand it completely. It looks like we can extend and override some methods from the DataSourceProxyBase class and add in this logger. Then point our setup to use that data source proxy.

Anyways, I think it would be a very good addition to the Logger.
Reply all
Reply to author
Forward
0 new messages