IDEMPIERE-4372 Performance: only add log record and sql statement to … (#172)
* IDEMPIERE-4372 Performance: only add log record and sql statement to context if trace/debug level <= debug/info Minor clean up and thread safe fix for CLogErrorBuffer and MIssue Only add LogRecord and SQL to context if TraceLevel is <= INFO * IDEMPIERE-4372 Performance: only add log record and sql statement to context if trace/debug level <= debug/info add back DB.isConnected check remove redundant CLogErrorBuffer call from DB.isConnected more fine grained synchronization
This commit is contained in:
parent
087b6e62d0
commit
cc76e63d85
|
@ -424,8 +424,10 @@ public class GridTable extends AbstractTableModel
|
|||
m_SQL += " ORDER BY " + m_orderClause;
|
||||
}
|
||||
//
|
||||
log.fine(m_SQL_Count);
|
||||
Env.setContext(m_ctx, m_WindowNo, m_TabNo, GridTab.CTX_SQL, m_SQL);
|
||||
if (log.isLoggable(Level.FINE))
|
||||
log.fine(m_SQL_Count);
|
||||
if (log.isLoggable(Level.INFO))
|
||||
Env.setContext(m_ctx, m_WindowNo, m_TabNo, GridTab.CTX_SQL, m_SQL);
|
||||
return m_SQL;
|
||||
} // createSelectSql
|
||||
|
||||
|
|
|
@ -53,9 +53,10 @@ public class MIssue extends X_AD_Issue
|
|||
*/
|
||||
public static MIssue create (LogRecord record)
|
||||
{
|
||||
s_log.config(record.getMessage());
|
||||
if (s_log.isLoggable(Level.CONFIG))
|
||||
s_log.config(record.getMessage());
|
||||
MSystem system = MSystem.get(Env.getCtx());
|
||||
if (!DB.isConnected()
|
||||
if (!DB.isConnected(false)
|
||||
|| system == null
|
||||
|| !system.isAutoErrorReport())
|
||||
return null;
|
||||
|
@ -406,7 +407,7 @@ public class MIssue extends X_AD_Issue
|
|||
public String report()
|
||||
{
|
||||
//if (true)
|
||||
return "-";
|
||||
return null;
|
||||
/*StringBuilder parameter = new StringBuilder("?");
|
||||
if (getRecord_ID() == 0) // don't report
|
||||
return "ID=0";
|
||||
|
|
|
@ -73,6 +73,11 @@ public class CLogErrorBuffer extends Handler
|
|||
setFilter(CLogFilter.get());
|
||||
} // initialize
|
||||
|
||||
private boolean isAddLogRecordToContext()
|
||||
{
|
||||
return CLogMgt.getLevelAsInt() <= Level.INFO.intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue Error
|
||||
* @return true if issue error
|
||||
|
@ -124,62 +129,83 @@ public class CLogErrorBuffer extends Handler
|
|||
*/
|
||||
public void publish (LogRecord record)
|
||||
{
|
||||
if (!isLoggable (record))
|
||||
return;
|
||||
|
||||
checkContext();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedList<LogRecord> m_logs = (LinkedList<LogRecord>) Env.getCtx().get(LOGS_KEY);
|
||||
if (!isLoggable (record) || m_logs == null)
|
||||
if (m_logs == null)
|
||||
return;
|
||||
|
||||
// Output
|
||||
synchronized (m_logs)
|
||||
if (isAddLogRecordToContext())
|
||||
{
|
||||
if (m_logs.size() >= LOG_SIZE)
|
||||
m_logs.removeFirst();
|
||||
m_logs.add(record);
|
||||
synchronized (m_logs)
|
||||
{
|
||||
if (m_logs.size() >= LOG_SIZE)
|
||||
m_logs.removeFirst();
|
||||
m_logs.add(record);
|
||||
}
|
||||
}
|
||||
|
||||
// We have an error
|
||||
if (record.getLevel() == Level.SEVERE)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedList<LogRecord> m_errors = (LinkedList<LogRecord>) Env.getCtx().get(ERRORS_KEY);
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedList<LogRecord[]> m_history = (LinkedList<LogRecord[]>) Env.getCtx().get(HISTORY_KEY);
|
||||
if (m_errors.size() >= ERROR_SIZE)
|
||||
if (isAddLogRecordToContext())
|
||||
{
|
||||
m_errors.removeFirst();
|
||||
m_history.removeFirst();
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedList<LogRecord> m_errors = (LinkedList<LogRecord>) Env.getCtx().get(ERRORS_KEY);
|
||||
synchronized (m_errors)
|
||||
{
|
||||
if (m_errors.size() >= ERROR_SIZE)
|
||||
{
|
||||
m_errors.removeFirst();
|
||||
}
|
||||
// Add Error
|
||||
m_errors.add(record);
|
||||
}
|
||||
}
|
||||
// Add Error
|
||||
m_errors.add(record);
|
||||
record.getSourceClassName(); // forces Class Name eval
|
||||
|
||||
// Create History
|
||||
ArrayList<LogRecord> history = new ArrayList<LogRecord>();
|
||||
for (int i = m_logs.size()-1; i >= 0; i--)
|
||||
if (isAddLogRecordToContext())
|
||||
{
|
||||
LogRecord rec = (LogRecord)m_logs.get(i);
|
||||
if (rec.getLevel() == Level.SEVERE)
|
||||
@SuppressWarnings("unchecked")
|
||||
LinkedList<LogRecord[]> m_history = (LinkedList<LogRecord[]>) Env.getCtx().get(HISTORY_KEY);
|
||||
ArrayList<LogRecord> history = new ArrayList<LogRecord>();
|
||||
synchronized (m_history)
|
||||
{
|
||||
if (history.size() == 0)
|
||||
history.add(rec);
|
||||
else
|
||||
break; // don't include previous error
|
||||
if (m_history.size() >= ERROR_SIZE)
|
||||
{
|
||||
m_history.removeFirst();
|
||||
}
|
||||
for (int i = m_logs.size()-1; i >= 0; i--)
|
||||
{
|
||||
LogRecord rec = (LogRecord)m_logs.get(i);
|
||||
if (rec.getLevel() == Level.SEVERE)
|
||||
{
|
||||
if (history.size() == 0)
|
||||
history.add(rec);
|
||||
else
|
||||
break; // don't include previous error
|
||||
}
|
||||
else
|
||||
{
|
||||
history.add(rec);
|
||||
if (history.size() > 10)
|
||||
break; // no more then 10 history records
|
||||
}
|
||||
|
||||
}
|
||||
LogRecord[] historyArray = new LogRecord[history.size()];
|
||||
int no = 0;
|
||||
for (int i = history.size()-1; i >= 0; i--)
|
||||
historyArray[no++] = (LogRecord)history.get(i);
|
||||
m_history.add(historyArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
history.add(rec);
|
||||
if (history.size() > 10)
|
||||
break; // no more then 10 history records
|
||||
}
|
||||
|
||||
}
|
||||
LogRecord[] historyArray = new LogRecord[history.size()];
|
||||
int no = 0;
|
||||
for (int i = history.size()-1; i >= 0; i--)
|
||||
historyArray[no++] = (LogRecord)history.get(i);
|
||||
m_history.add(historyArray);
|
||||
// Issue Reporting
|
||||
if (isIssueError())
|
||||
{
|
||||
|
@ -199,12 +225,11 @@ public class CLogErrorBuffer extends Handler
|
|||
&& loggerName.indexOf("CConnection") == -1
|
||||
)
|
||||
{
|
||||
setIssueError(false);
|
||||
try
|
||||
{
|
||||
MIssue.create(record);
|
||||
setIssueError(true);
|
||||
} catch (Throwable e)
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
//failed to save exception to db, print to console
|
||||
System.err.println(getFormatter().format(record));
|
||||
|
|
|
@ -339,11 +339,6 @@ public final class DB
|
|||
|
||||
//direct connection
|
||||
boolean success = false;
|
||||
CLogErrorBuffer eb = CLogErrorBuffer.get(false);
|
||||
if (eb != null && eb.isIssueError())
|
||||
eb.setIssueError(false);
|
||||
else
|
||||
eb = null; // don't reset
|
||||
try
|
||||
{
|
||||
Connection conn = getConnectionRW(createNew); // try to get a connection
|
||||
|
@ -358,8 +353,6 @@ public final class DB
|
|||
{
|
||||
success = false;
|
||||
}
|
||||
if (eb != null)
|
||||
eb.setIssueError(true);
|
||||
return success;
|
||||
} // isConnected
|
||||
|
||||
|
|
|
@ -2356,7 +2356,8 @@ public class FindWindow extends Window implements EventListener<Event>, ValueCha
|
|||
String finalSQL = MRole.getDefault().addAccessSQL(sql.toString(),
|
||||
m_tableName, MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
|
||||
finalSQL = Env.parseContext(Env.getCtx(), m_targetWindowNo, finalSQL, false);
|
||||
Env.setContext(Env.getCtx(), m_targetWindowNo, TABNO, GridTab.CTX_FindSQL, finalSQL);
|
||||
if (log.isLoggable(Level.INFO))
|
||||
Env.setContext(Env.getCtx(), m_targetWindowNo, TABNO, GridTab.CTX_FindSQL, finalSQL);
|
||||
|
||||
// Execute Qusery
|
||||
m_total = 999999;
|
||||
|
|
Loading…
Reference in New Issue