-
Notifications
You must be signed in to change notification settings - Fork 82
added layout #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added layout #145
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -29,6 +29,7 @@ | |||||||||||||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||||||||||||||
import ch.qos.logback.classic.spi.IThrowableProxy; | ||||||||||||||
import ch.qos.logback.classic.spi.ThrowableProxy; | ||||||||||||||
import ch.qos.logback.core.Layout; | ||||||||||||||
import ch.qos.logback.core.encoder.EncoderBase; | ||||||||||||||
import co.elastic.logging.AdditionalField; | ||||||||||||||
import co.elastic.logging.EcsJsonSerializer; | ||||||||||||||
|
@@ -54,6 +55,7 @@ public class EcsEncoder extends EncoderBase<ILoggingEvent> { | |||||||||||||
private boolean includeOrigin; | ||||||||||||||
private final List<AdditionalField> additionalFields = new ArrayList<AdditionalField>(); | ||||||||||||||
private OutputStream os; | ||||||||||||||
protected Layout<ILoggingEvent> layout; | ||||||||||||||
|
||||||||||||||
@Override | ||||||||||||||
public byte[] headerBytes() { | ||||||||||||||
|
@@ -103,7 +105,7 @@ public byte[] encode(ILoggingEvent event) { | |||||||||||||
StringBuilder builder = new StringBuilder(256); | ||||||||||||||
EcsJsonSerializer.serializeObjectStart(builder, event.getTimeStamp()); | ||||||||||||||
EcsJsonSerializer.serializeLogLevel(builder, event.getLevel().toString()); | ||||||||||||||
EcsJsonSerializer.serializeFormattedMessage(builder, event.getFormattedMessage()); | ||||||||||||||
serializeMessage(event, builder); | ||||||||||||||
EcsJsonSerializer.serializeEcsVersion(builder); | ||||||||||||||
serializeMarkers(event, builder); | ||||||||||||||
EcsJsonSerializer.serializeServiceName(builder, serviceName); | ||||||||||||||
|
@@ -136,6 +138,14 @@ public byte[] encode(ILoggingEvent event) { | |||||||||||||
return builder.toString().getBytes(UTF_8); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private void serializeMessage(ILoggingEvent event, StringBuilder builder) { | ||||||||||||||
if(layout == null) { | ||||||||||||||
EcsJsonSerializer.serializeFormattedMessage(builder, event.getFormattedMessage()); | ||||||||||||||
} else { | ||||||||||||||
EcsJsonSerializer.serializeFormattedMessage(builder, this.layout.doLayout(event)); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Subclasses can override this to add custom fields. | ||||||||||||||
* The last character in the StringBuilder will be comma when this is called. | ||||||||||||||
|
@@ -198,4 +208,11 @@ public void setEventDataset(String eventDataset) { | |||||||||||||
public void setThrowableConverter(ThrowableHandlingConverter throwableConverter) { | ||||||||||||||
this.throwableConverter = throwableConverter; | ||||||||||||||
} | ||||||||||||||
public Layout<ILoggingEvent> getLayout() { | ||||||||||||||
return this.layout; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
Comment on lines
+211
to
+214
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No need for a getter |
||||||||||||||
public void setLayout(Layout<ILoggingEvent> layout) { | ||||||||||||||
this.layout = layout; | ||||||||||||||
} | ||||||||||||||
Comment on lines
+215
to
+217
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Add a javadoc saying this |
||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.