[logback-user] Xml to Java code, logstash encoder

kypdk kypdkz at gmail.com
Wed Feb 14 09:22:13 UTC 2024


Hello Guys


I want to create the logstash encoder you see in xml with Java code.  But
there is no method to set the pattern.  Which method should I do?

<appender name="STASH"
class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logback/uptLog.log</file>
    <rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>logback/uptLog.%d{yyyy-MM-dd}.log</fileNamePattern>
    </rollingPolicy>
    <encoder class="net.logstash.logback.encoder.LogstashEncoder">
        <charset>UTF-8</charset>
        <pattern>
            %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} -
%X{requestId} %msg%n%exception{full}
        </pattern>
    </encoder>
</appender>



net.logstash.logback.encoder.LogstashEncoder logstashEncoder = new
LogstashEncoder();
logstashEncoder.setContext(loggerContext);
logstashEncoder.start();


Regars
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20240214/7c1a4ce4/attachment.htm>


More information about the logback-user mailing list