mirror of https://github.com/status-im/timbre.git
[#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:
parent
ef8592f27d
commit
e9c5dc0479
|
@ -50,10 +50,12 @@
|
||||||
format to the logstash server at `host:port`. Additionally `opts`
|
format to the logstash server at `host:port`. Additionally `opts`
|
||||||
may be a map with `:pr-stracktrace` mapped to a function taking an
|
may be a map with `:pr-stracktrace` mapped to a function taking an
|
||||||
exception, which should write the stacktrace of that exception to
|
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]]
|
[host port & [opts]]
|
||||||
(let [conn (atom nil)
|
(let [conn (atom nil)
|
||||||
nl "\n"]
|
flush? (or (:flush? opts) false)
|
||||||
|
nl "\n"]
|
||||||
{:enabled? true
|
{:enabled? true
|
||||||
:async? false
|
:async? false
|
||||||
:min-level nil
|
:min-level nil
|
||||||
|
@ -63,12 +65,13 @@
|
||||||
(fn [data]
|
(fn [data]
|
||||||
(try
|
(try
|
||||||
(let [[sock out] (swap! conn
|
(let [[sock out] (swap! conn
|
||||||
(fn [conn]
|
(fn [conn]
|
||||||
(or (and conn (connection-ok? conn) conn)
|
(or (and conn (connection-ok? conn) conn)
|
||||||
(connect host port))))]
|
(connect host port))))]
|
||||||
(locking sock
|
(locking sock
|
||||||
(data->json-stream data out (select-keys opts [:pr-stacktrace]))
|
(data->json-stream data out (select-keys opts [:pr-stacktrace]))
|
||||||
;; logstash tcp input plugin: "each event is assumed to be one line of text".
|
;; 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 _
|
(catch java.io.IOException _
|
||||||
nil)))}))
|
nil)))}))
|
||||||
|
|
Loading…
Reference in New Issue