Java Code Examples for ch.qos.logback.core.OutputStreamAppender#getEncoder()

The following examples show how to use ch.qos.logback.core.OutputStreamAppender#getEncoder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogBackConfiguration.java    From summerframework with Apache License 2.0 5 votes vote down vote up
private void setLayout(LoggerContext loggerContext,OutputStreamAppender outputStreamAppender){
    Encoder<?> encoder = outputStreamAppender.getEncoder();
    if (encoder instanceof LayoutWrappingEncoder) {
        TraceIdPatternLogbackLayout traceIdLayOut = new TraceIdPatternLogbackLayout();
        traceIdLayOut.setContext(loggerContext);
        traceIdLayOut.setPattern(getLogBackPattern());
        traceIdLayOut.start();
        Field field = ReflectionUtils.findField(encoder.getClass(), "layout");
        field.setAccessible(true);
        ReflectionUtils.setField(field, encoder, traceIdLayOut);
    }
}
 
Example 2
Source File: LogstashTests.java    From godaddy-logger with MIT License 5 votes vote down vote up
private Map<String, Object> getJson() throws IOException {
    OutputStreamAppender<ILoggingEvent> appender = (OutputStreamAppender<ILoggingEvent>) testLogger.getAppender("loggingEventCompositeJsonEncoderAppender");
    LoggingEventCompositeJsonEncoder encoder = (LoggingEventCompositeJsonEncoder) appender.getEncoder();

    String encodedValue = new String(encoder.encode(listAppender.list.get(0)), "UTF-8");

    return jsonFactory.createParser(encodedValue).readValueAs(new TypeReference<Map<String, Object>>() {});
}