mirror of https://github.com/status-im/timbre.git
Housekeeping for #147
This commit is contained in:
parent
df96b2ba58
commit
f8a83fd798
|
@ -1,5 +1,11 @@
|
|||
> This project uses [Break Versioning](https://github.com/ptaoussanis/encore/blob/master/BREAK-VERSIONING.md) as of **Aug 16, 2014**.
|
||||
|
||||
## Pending
|
||||
|
||||
* **New**: added 3rd-party gelf appender [#147 @davewo]
|
||||
|
||||
|
||||
|
||||
## v4.2.1 / 2016 Jan 14
|
||||
|
||||
> This is a non-breaking hotfix release
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
(ns taoensso.timbre.appenders.3rd-party.gelf
|
||||
(:import (org.graylog2.gelfclient
|
||||
GelfConfiguration
|
||||
GelfMessageBuilder
|
||||
GelfTransports
|
||||
GelfMessageLevel)
|
||||
(java.net InetSocketAddress)))
|
||||
"Appender to handle sending messages in the gelf format to a centralized
|
||||
logging server (e.g. Graylog)"
|
||||
{:author "Dave Owens (@davewo)"}
|
||||
(:import
|
||||
[org.graylog2.gelfclient
|
||||
GelfConfiguration
|
||||
GelfMessageBuilder
|
||||
GelfTransports
|
||||
GelfMessageLevel]
|
||||
[java.net InetSocketAddress]))
|
||||
|
||||
(defn timbre-to-gelf-level [level]
|
||||
(let [gelf-levels {:info GelfMessageLevel/INFO
|
||||
:warn GelfMessageLevel/WARNING
|
||||
:error GelfMessageLevel/ERROR
|
||||
:fatal GelfMessageLevel/CRITICAL}]
|
||||
(let [gelf-levels
|
||||
{:info GelfMessageLevel/INFO
|
||||
:warn GelfMessageLevel/WARNING
|
||||
:error GelfMessageLevel/ERROR
|
||||
:fatal GelfMessageLevel/CRITICAL}]
|
||||
|
||||
(defn timbre-to-gelf-level [level]
|
||||
(get gelf-levels level GelfMessageLevel/WARNING)))
|
||||
|
||||
(defn make-gelf-transport
|
||||
"Make a new GelfTransport object, capable of sending a GelfMessage to a remote server.
|
||||
|
||||
Parameters:
|
||||
*`host` - An IP address or hostname string of the remote logging server.
|
||||
*`port` - The TCP or UDP port on which the server listens.
|
||||
*`protocol` - Use :tcp or :udp transport to send messages.
|
||||
|
||||
Returns a new GelfTransport object."
|
||||
"Returns a new GelfTransport object, capable of sending a GelfMessage to a
|
||||
remote server. Params:
|
||||
`host` - IP address or hostname string of the remote logging server
|
||||
`port` - TCP or UDP port on which the server listens
|
||||
`protocol` - e/o #{:tcp :udp}"
|
||||
[host port protocol]
|
||||
{:pre [(or (= :udp protocol) (= :tcp protocol))]}
|
||||
{:pre [(#{:udp :tcp} protocol)]}
|
||||
(let [protocols {:udp GelfTransports/UDP :tcp GelfTransports/TCP}
|
||||
transport (protocol protocols)
|
||||
config (-> (GelfConfiguration. (InetSocketAddress. host port)) (.transport transport))]
|
||||
config (-> (GelfConfiguration. (InetSocketAddress. host port))
|
||||
(.transport transport))]
|
||||
(GelfTransports/create config)))
|
||||
|
||||
(defn gelf-appender
|
||||
"A timbre appender capable of sending gelf messages to a remote host.
|
||||
|
||||
Parameters:
|
||||
*`gelf-server` - An IP address or hostname string of the remote logging server.
|
||||
*`port` - the TCP or UDP port on which the server listens.
|
||||
*`protocol` - OPTIONAL, Use :tcp or :udp (default) transport to send messages.
|
||||
|
||||
Returns a map, where :fn is the function timbre will call with a log message."
|
||||
([gelf-server port] (gelf-appender gelf-server port :udp))
|
||||
"Returns a Timbre appender that sends gelf messages to a remote host. Params:
|
||||
`gelf-server` - IP address or hostname string of the remote logging server
|
||||
`port` - TCP or UDP port on which the server listens
|
||||
`protocol` - e/o #{:tcp :udp}, defaults to :udp"
|
||||
([gelf-server port ] (gelf-appender gelf-server port :udp))
|
||||
([gelf-server port protocol]
|
||||
(let [tranport (make-gelf-transport gelf-server port protocol)]
|
||||
{:enabled? true
|
||||
|
@ -47,11 +47,11 @@
|
|||
:rate-limit nil
|
||||
:output-fn :inherit
|
||||
:gelf-transport tranport
|
||||
|
||||
:fn (fn [data]
|
||||
(let [{:keys [appender msg_ level hostname_]} data
|
||||
gelf-transport (:gelf-transport appender)
|
||||
log-level (timbre-to-gelf-level level)
|
||||
gelf-message (-> (GelfMessageBuilder. @msg_ @hostname_)
|
||||
(.level log-level) .build)]
|
||||
(.send gelf-transport gelf-message)))})))
|
||||
:fn
|
||||
(fn [data]
|
||||
(let [{:keys [appender msg_ level hostname_]} data
|
||||
gelf-transport (:gelf-transport appender)
|
||||
log-level (timbre-to-gelf-level level)
|
||||
gelf-message (-> (GelfMessageBuilder. (force msg_) (force hostname_))
|
||||
(.level log-level) .build)]
|
||||
(.send gelf-transport gelf-message)))})))
|
||||
|
|
Loading…
Reference in New Issue