I'm developing a Kotlin application that uses a PostgreSQL database via Exposed. I'm trying to debug an error and I would like to see what SQL is sent to the database. The driver docs says it uses java.util.logging
. How can I configure it so that SQL appears on the console, just for debugging purposes?
I'm asking for a quick and dirty hack to aid in debugging, so I would prefer avoiding a logging configuration file and configure everything in code, if possible.
I tried the code below, but only the SQL code of the line that throws is printed, alongside with the stack trace of the exception:
val logger = Logger.getLogger("org.postgresql")
logger.level = Level.ALL
val handler = ConsoleHandler()
handler.level = Level.ALL
handler.formatter = SimpleFormatter()
logger.addHandler(handler)
Database.connect(
"jdbc:postgresql://localhost:5432/money",
driver = "org.postgresql.Driver",
user = "***",
password = "***"
)
MyTable.batchInsert(/*...*/) {/*...*/} // When I execute this I want the SQL to appear on the console
MyOtherTable.batchInsert(/*...*/) {/*...*/} // This is the line that throws an exception
You can try adding logging.
And add
logback.xml
to your resources.This is the code for my case.