26 Aralık 2022 Pazartesi

Log4j2 JsonLayout Tanımlama

Örnek
Şöyle yaparız
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <JsonLayout complete="false"  compact="true" eventEol="true"></JsonLayout>
      <PatternLayout
        pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%t}{bright,blue}]
        %style{%C{1.}}{bright,yellow}: %msg%n%throwable" />
    </Console>
  </Appenders>
  <Loggers>
    <!-- LOG everything at INFO level -->
    <Root level="info">
      <AppenderRef ref="Console" />
     </Root>
   <Logger name="com.vb" level="trace"></Logger>
 </Loggers>
</Configuration>
Çıktısı şöyle
{
  "thread": "main",
  "level": "INFO",
  "loggerName": "com.vb.math.learnit.LearnitApplication",
  "message": "Started LearnitApplication in 2.508 seconds (JVM running for 4.586)",
  "endOfBatch": false,
  "loggerFqcn": "org.apache.commons.logging.LogAdapter$Log4jLog",
  "instant": {
    "epochSecond": 1597070439,
    "nanoOfSecond": 853000000
  },
  "threadId": 1,
  "threadPriority": 5
}

Hiç yorum yok:

Yorum Gönder