Skip to content

Commit

Permalink
When logging under an AsyncAppender timestamps were being reported at…
Browse files Browse the repository at this point in the history
… the time that the log event was sent, which could be many seconds after when the log event occurred. Now timestamps are extracted from the original log event instead of being calculated when they're sent over the wire.
  • Loading branch information
John Currier authored and John Currier committed Jun 25, 2021
1 parent 4b98682 commit 1add4e5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class HttpEventCollectorEventInfo {

/**
* Create a new HttpEventCollectorEventInfo container
* @param timeMsSinceEpoch in milliseconds since "unix epoch"
* @param severity of event
* @param message is an event content
* @param logger_name name of the logger
Expand All @@ -45,6 +46,7 @@ public class HttpEventCollectorEventInfo {
* @param marker event marker
*/
public HttpEventCollectorEventInfo(
final long timeMsSinceEpoch,
final String severity,
final String message,
final String logger_name,
Expand All @@ -53,7 +55,7 @@ public HttpEventCollectorEventInfo(
final String exception_message,
final Serializable marker
) {
this.time = System.currentTimeMillis() / 1000.0;
this.time = timeMsSinceEpoch / 1000.0;
this.severity = severity;
this.message = message;
this.logger_name = logger_name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public void append(final LogEvent event)
{
// if an exception was thrown
this.sender.send(
event.getTimeMillis(),
event.getLevel().toString(),
getLayout().toSerializable(event).toString(),
includeLoggerName ? event.getLoggerName() : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ private void sendEvent(ILoggingEvent event) {
MarkerConverter c = new MarkerConverter();
if (this.started) {
this.sender.send(
event.getTimeStamp(),
event.getLevel().toString(),
_layout.doLayout((E) event),
_includeLoggerName ? event.getLoggerName() : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public HttpEventCollectorLoggingHandler() {
@Override
public void publish(LogRecord record) {
this.sender.send(
record.getMillis(),
record.getLevel().toString(),
record.getMessage(),
includeLoggerName ? record.getLoggerName() : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public void addMiddleware(HttpEventCollectorMiddleware.HttpSenderMiddleware midd
* @param message event text
*/
public synchronized void send(
final long timeMsSinceEpoch,
final String severity,
final String message,
final String logger_name,
Expand All @@ -177,7 +178,7 @@ public synchronized void send(
) {
// create event info container and add it to the batch
HttpEventCollectorEventInfo eventInfo =
new HttpEventCollectorEventInfo(severity, message, logger_name, thread_name, properties, exception_message, marker);
new HttpEventCollectorEventInfo(timeMsSinceEpoch, severity, message, logger_name, thread_name, properties, exception_message, marker);
eventsBatch.add(eventInfo);
eventsBatchSize += severity.length() + message.length();
if (eventsBatch.size() >= maxEventsBatchCount || eventsBatchSize > maxEventsBatchSize) {
Expand All @@ -190,7 +191,7 @@ public synchronized void send(
* @param message event text
*/
public synchronized void send(final String message) {
send("", message, "", "", null, null, "");
send(System.currentTimeMillis(), "", message, "", "", null, null, "");
}

/**
Expand Down

0 comments on commit 1add4e5

Please sign in to comment.