Skip to content

Commit

Permalink
Merge pull request #186 from johncurrier/Delayed_timestamps_with_Asyn…
Browse files Browse the repository at this point in the history
…cAppender

Delayed time when using AsyncAppender
  • Loading branch information
fantavlik committed Jul 26, 2021
2 parents 18a2916 + 1add4e5 commit 2ef42f3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
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
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
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
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
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 2ef42f3

Please sign in to comment.