2016-07-08 184 views
1

根據我的要求,我只是想發佈http消息到org.slf4j.LoggerFactory.getLogger()記錄的另一端。logback appender發佈消息爲http消息

以下json字符串登錄在INFO level

{

"studentName": "My Name", 
"Deratment": "Computer Science", 
"address": { 
    "Address Line1": "My Address Line1", 
    "Address Line2": "My Address Line2", 
    "Address Line3": "My Address Line3" 
} 

}

考慮,

  1. HTTP消息應用的MIME類型張貼application/json

  2. INFO水平不是全部僅處理特定的日誌。

在logback中是否有任何內置的appender來實現這一點?

如果不是,最好的辦法是什麼?

回答

1

Logback與logstash運行得很好:https://github.com/logstash/logstash-logback-encoder

第一步是將logback配置爲logstash連接。

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> 
     <destination>127.0.0.1:4560</destination> 

     <!-- encoder is required --> 
     <encoder class="net.logstash.logback.encoder.LogstashEncoder" /> 
    </appender> 

    <root level="DEBUG"> 
     <appender-ref ref="stash" /> 
    </root> 
</configuration> 

一旦完成,你需要創建一個從TCP輸入到http輸出插件管道可能如下所示

input { 
    tcp { 
      port => 4560 
      codec => json_lines 
     } 
} 

output { 
    http { 
     http_method => ... 
     url => ... 
    } 
} 

(見https://www.elastic.co/guide/en/logstash/current/plugins-outputs-http.html