[#195] Logstash appender: add `:flush?` option (@tvanhens)

Setting the value to true will eagerly flush the tcp writer. Default
behavior is for this to be false.
This commit is contained in:
Tyler van Hensbergen 2016-09-15 12:40:42 -06:00 committed by Peter Taoussanis
parent ef8592f27d
commit e9c5dc0479
1 changed files with 10 additions and 7 deletions

View File

@ -50,9 +50,11 @@
format to the logstash server at `host:port`. Additionally `opts`
may be a map with `:pr-stracktrace` mapped to a function taking an
exception, which should write the stacktrace of that exception to
`*out`."
`*out`. Set `:flush?` to true to flush the writer after every
event."
[host port & [opts]]
(let [conn (atom nil)
flush? (or (:flush? opts) false)
nl "\n"]
{:enabled? true
:async? false
@ -69,6 +71,7 @@
(locking sock
(data->json-stream data out (select-keys opts [:pr-stacktrace]))
;; logstash tcp input plugin: "each event is assumed to be one line of text".
(.write ^java.io.Writer out nl)))
(.write ^java.io.Writer out nl)
(when flush? (.flush ^java.io.Writer out))))
(catch java.io.IOException _
nil)))}))