Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
*
* @author Moritz Halbritter
* @author Phillip Webb
* @author Yanming Zhou
* @see StructuredLogFormatter
*/
@Plugin(name = "StructuredLogLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE)
Expand All @@ -58,12 +59,26 @@ private StructuredLogLayout(Charset charset, StructuredLogFormatter<LogEvent> fo

@Override
public String toSerializable(LogEvent event) {
return this.formatter.format(event);
try {
return this.formatter.format(event);
}
catch (RuntimeException ex) {
// exception can not be logged due to "Chicken-and-egg" problem
ex.printStackTrace(System.err);
throw ex;
}
}

@Override
public byte[] toByteArray(LogEvent event) {
return this.formatter.formatAsBytes(event, (getCharset() != null) ? getCharset() : StandardCharsets.UTF_8);
try {
return this.formatter.formatAsBytes(event, (getCharset() != null) ? getCharset() : StandardCharsets.UTF_8);
}
catch (RuntimeException ex) {
// exception can not be logged due to "Chicken-and-egg" problem
ex.printStackTrace(System.err);
throw ex;
}
}

@PluginBuilderFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
*
* @author Moritz Halbritter
* @author Phillip Webb
* @author Yanming Zhou
* @since 3.4.0
* @see StructuredLogFormatter
*/
Expand Down Expand Up @@ -124,7 +125,14 @@ public byte[] headerBytes() {

@Override
public byte[] encode(ILoggingEvent event) {
return this.formatter.formatAsBytes(event, (this.charset != null) ? this.charset : StandardCharsets.UTF_8);
try {
return this.formatter.formatAsBytes(event, (this.charset != null) ? this.charset : StandardCharsets.UTF_8);
}
catch (RuntimeException ex) {
// exception can not be logged due to "Chicken-and-egg" problem
ex.printStackTrace(System.err);
throw ex;
}
}

@Override
Expand Down
Loading