Skip to content

Commit

Permalink
[fix](auditloader) support audit table millisecond and fix stmt trunc…
Browse files Browse the repository at this point in the history
…ated by '\r'

Signed-off-by: nextdreamblue <[email protected]>
  • Loading branch information
nextdreamblue committed Jan 3, 2024
1 parent 8f2b829 commit 877e911
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class AuditLoaderPlugin extends Plugin implements AuditPlugin {
private final static Logger LOG = LogManager.getLogger(AuditLoaderPlugin.class);

private static final ThreadLocal<SimpleDateFormat> dateFormatContainer = ThreadLocal.withInitial(
() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"));

private StringBuilder auditLogBuffer = new StringBuilder();
private StringBuilder slowLogBuffer = new StringBuilder();
Expand Down Expand Up @@ -179,7 +179,9 @@ private void fillLogBuffer(AuditEvent event, StringBuilder logBuffer) {
logBuffer.append(event.peakMemoryBytes).append("\t");
// trim the query to avoid too long
// use `getBytes().length` to get real byte length
String stmt = truncateByBytes(event.stmt).replace("\n", " ").replace("\t", " ");
String stmt = truncateByBytes(event.stmt).replace("\n", " ")
.replace("\t", " ")
.replace("\r", " ");
LOG.debug("receive audit event with stmt: {}", stmt);
logBuffer.append(stmt).append("\n");
}
Expand Down Expand Up @@ -338,7 +340,7 @@ public void run() {

public static String longToTimeString(long timeStamp) {
if (timeStamp <= 0L) {
return "1900-01-01 00:00:00";
return "1900-01-01 00:00:00.000";
}
return dateFormatContainer.get().format(new Date(timeStamp));
}
Expand Down

0 comments on commit 877e911

Please sign in to comment.