Skip to content

Commit

Permalink
Config work and Gelf Encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
agentgt committed Jan 17, 2024
1 parent 928da9a commit ccdbcdc
Show file tree
Hide file tree
Showing 7 changed files with 637 additions and 18 deletions.
34 changes: 34 additions & 0 deletions core/src/main/java/io/jstach/rainbowgum/LogEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ default void formattedMessage(Appendable a) {
*/
public LogEvent freeze();

/**
* Freeze and replace with the given timestamp.
* @param timestamp instant to replace timestamp in this.
* @return a copy of this with the given timestamp.
*/
public LogEvent freeze(Instant timestamp);

}

enum EmptyLogEvent implements LogEvent {
Expand Down Expand Up @@ -276,6 +283,11 @@ public LogEvent freeze() {
return this;
}

@Override
public LogEvent freeze(Instant timestamp) {
return this;
}

}

record OneArgLogEvent(Instant timestamp, String threadName, long threadId, System.Logger.Level level, String loggerName,
Expand All @@ -295,6 +307,10 @@ public int argCount() {
}

public LogEvent freeze() {
return freeze(timestamp);
}

public LogEvent freeze(Instant timestamp) {
StringBuilder sb = new StringBuilder(message.length());
formattedMessage(sb);
return new DefaultLogEvent(timestamp, threadName, threadId, level, loggerName, sb.toString(),
Expand All @@ -320,6 +336,10 @@ public int argCount() {
}

public LogEvent freeze() {
return freeze(timestamp);
}

public LogEvent freeze(Instant timestamp) {
StringBuilder sb = new StringBuilder(message.length());
formattedMessage(sb);
return new DefaultLogEvent(timestamp, threadName, threadId, level, loggerName, sb.toString(),
Expand All @@ -344,11 +364,16 @@ public int argCount() {
}

public LogEvent freeze() {
return freeze(timestamp);
}

public LogEvent freeze(Instant timestamp) {
StringBuilder sb = new StringBuilder(message.length());
formattedMessage(sb);
return new DefaultLogEvent(timestamp, threadName, threadId, level, loggerName, sb.toString(),
keyValues.freeze(), null);
}

}

record DefaultLogEvent(Instant timestamp, String threadName, long threadId, System.Logger.Level level,
Expand Down Expand Up @@ -379,4 +404,13 @@ public LogEvent freeze() {
return this;
}

public LogEvent freeze(Instant timestamp) {
if (keyValues instanceof MutableKeyValues mkvs) {
return new DefaultLogEvent(timestamp, threadName, threadId, level, loggerName, formattedMessage, mkvs,
throwable);
}
return new DefaultLogEvent(timestamp, threadName, threadId, level, loggerName, formattedMessage, keyValues,
throwable);
}

}
Loading

0 comments on commit ccdbcdc

Please sign in to comment.