mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Add option to (poorly) format SQL for logs
This commit is contained in:
@ -987,6 +987,16 @@ public abstract class AbstractRDBMSAction implements QActionInterface
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Make it easy (e.g., for tests) to turn on poor-man's formatting of SQL
|
||||||
|
*******************************************************************************/
|
||||||
|
public static void setLogSQLReformat(boolean doReformat)
|
||||||
|
{
|
||||||
|
System.setProperty("qqq.rdbms.logSQL.reformat", String.valueOf(doReformat));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
**
|
**
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
@ -998,6 +1008,19 @@ public abstract class AbstractRDBMSAction implements QActionInterface
|
|||||||
{
|
{
|
||||||
params = params.size() <= 100 ? params : params.subList(0, 99);
|
params = params.size() <= 100 ? params : params.subList(0, 99);
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// (very very) poor man's version of sql formatting... if property is true //
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
if(System.getProperty("qqq.rdbms.logSQL.reformat", "false").equalsIgnoreCase("true"))
|
||||||
|
{
|
||||||
|
sql = Objects.requireNonNullElse(sql, "").toString()
|
||||||
|
.replaceAll("FROM ", "\nFROM\n ")
|
||||||
|
.replaceAll("INNER", "\n INNER")
|
||||||
|
.replaceAll("LEFT", "\n LEFT")
|
||||||
|
.replaceAll("RIGHT", "\n RIGHT")
|
||||||
|
.replaceAll("WHERE", "\nWHERE\n ");
|
||||||
|
}
|
||||||
|
|
||||||
if(System.getProperty("qqq.rdbms.logSQL.output", "logger").equalsIgnoreCase("system.out"))
|
if(System.getProperty("qqq.rdbms.logSQL.output", "logger").equalsIgnoreCase("system.out"))
|
||||||
{
|
{
|
||||||
System.out.println("SQL: " + sql);
|
System.out.println("SQL: " + sql);
|
||||||
|
Reference in New Issue
Block a user