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**.
|
> 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
|
## v4.2.1 / 2016 Jan 14
|
||||||
|
|
||||||
> This is a non-breaking hotfix release
|
> This is a non-breaking hotfix release
|
||||||
|
|
|
@ -1,44 +1,44 @@
|
||||||
(ns taoensso.timbre.appenders.3rd-party.gelf
|
(ns taoensso.timbre.appenders.3rd-party.gelf
|
||||||
(:import (org.graylog2.gelfclient
|
"Appender to handle sending messages in the gelf format to a centralized
|
||||||
GelfConfiguration
|
logging server (e.g. Graylog)"
|
||||||
GelfMessageBuilder
|
{:author "Dave Owens (@davewo)"}
|
||||||
GelfTransports
|
(:import
|
||||||
GelfMessageLevel)
|
[org.graylog2.gelfclient
|
||||||
(java.net InetSocketAddress)))
|
GelfConfiguration
|
||||||
|
GelfMessageBuilder
|
||||||
|
GelfTransports
|
||||||
|
GelfMessageLevel]
|
||||||
|
[java.net InetSocketAddress]))
|
||||||
|
|
||||||
(defn timbre-to-gelf-level [level]
|
(let [gelf-levels
|
||||||
(let [gelf-levels {:info GelfMessageLevel/INFO
|
{:info GelfMessageLevel/INFO
|
||||||
:warn GelfMessageLevel/WARNING
|
:warn GelfMessageLevel/WARNING
|
||||||
:error GelfMessageLevel/ERROR
|
:error GelfMessageLevel/ERROR
|
||||||
:fatal GelfMessageLevel/CRITICAL}]
|
:fatal GelfMessageLevel/CRITICAL}]
|
||||||
|
|
||||||
|
(defn timbre-to-gelf-level [level]
|
||||||
(get gelf-levels level GelfMessageLevel/WARNING)))
|
(get gelf-levels level GelfMessageLevel/WARNING)))
|
||||||
|
|
||||||
(defn make-gelf-transport
|
(defn make-gelf-transport
|
||||||
"Make a new GelfTransport object, capable of sending a GelfMessage to a remote server.
|
"Returns a new GelfTransport object, capable of sending a GelfMessage to a
|
||||||
|
remote server. Params:
|
||||||
Parameters:
|
`host` - IP address or hostname string of the remote logging server
|
||||||
*`host` - An IP address or hostname string of the remote logging server.
|
`port` - TCP or UDP port on which the server listens
|
||||||
*`port` - The TCP or UDP port on which the server listens.
|
`protocol` - e/o #{:tcp :udp}"
|
||||||
*`protocol` - Use :tcp or :udp transport to send messages.
|
|
||||||
|
|
||||||
Returns a new GelfTransport object."
|
|
||||||
[host port protocol]
|
[host port protocol]
|
||||||
{:pre [(or (= :udp protocol) (= :tcp protocol))]}
|
{:pre [(#{:udp :tcp} protocol)]}
|
||||||
(let [protocols {:udp GelfTransports/UDP :tcp GelfTransports/TCP}
|
(let [protocols {:udp GelfTransports/UDP :tcp GelfTransports/TCP}
|
||||||
transport (protocol protocols)
|
transport (protocol protocols)
|
||||||
config (-> (GelfConfiguration. (InetSocketAddress. host port)) (.transport transport))]
|
config (-> (GelfConfiguration. (InetSocketAddress. host port))
|
||||||
|
(.transport transport))]
|
||||||
(GelfTransports/create config)))
|
(GelfTransports/create config)))
|
||||||
|
|
||||||
(defn gelf-appender
|
(defn gelf-appender
|
||||||
"A timbre appender capable of sending gelf messages to a remote host.
|
"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
|
||||||
Parameters:
|
`port` - TCP or UDP port on which the server listens
|
||||||
*`gelf-server` - An IP address or hostname string of the remote logging server.
|
`protocol` - e/o #{:tcp :udp}, defaults to :udp"
|
||||||
*`port` - the TCP or UDP port on which the server listens.
|
([gelf-server port ] (gelf-appender gelf-server port :udp))
|
||||||
*`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))
|
|
||||||
([gelf-server port protocol]
|
([gelf-server port protocol]
|
||||||
(let [tranport (make-gelf-transport gelf-server port protocol)]
|
(let [tranport (make-gelf-transport gelf-server port protocol)]
|
||||||
{:enabled? true
|
{:enabled? true
|
||||||
|
@ -47,11 +47,11 @@
|
||||||
:rate-limit nil
|
:rate-limit nil
|
||||||
:output-fn :inherit
|
:output-fn :inherit
|
||||||
:gelf-transport tranport
|
:gelf-transport tranport
|
||||||
|
:fn
|
||||||
:fn (fn [data]
|
(fn [data]
|
||||||
(let [{:keys [appender msg_ level hostname_]} data
|
(let [{:keys [appender msg_ level hostname_]} data
|
||||||
gelf-transport (:gelf-transport appender)
|
gelf-transport (:gelf-transport appender)
|
||||||
log-level (timbre-to-gelf-level level)
|
log-level (timbre-to-gelf-level level)
|
||||||
gelf-message (-> (GelfMessageBuilder. @msg_ @hostname_)
|
gelf-message (-> (GelfMessageBuilder. (force msg_) (force hostname_))
|
||||||
(.level log-level) .build)]
|
(.level log-level) .build)]
|
||||||
(.send gelf-transport gelf-message)))})))
|
(.send gelf-transport gelf-message)))})))
|
||||||
|
|
Loading…
Reference in New Issue