Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure short_message is not empty + add extra fields #233

Merged
merged 1 commit into from
Apr 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/taoensso/timbre/appenders/3rd_party/gelf.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@
(.transport transport))]
(GelfTransports/create config)))

(defn data->gelf-message
[data]
(let [{:keys [msg_ hostname_
level instant
context ?err ?ns-str
?file ?line]}
data

log-level (timbre-to-gelf-level level)
msg (or (and (not-empty (force msg_))
(force msg_))
(and ?err
(.getMessage ?err))
"EMPTY MSG")
msg-builder (-> (GelfMessageBuilder. msg (force hostname_))
(.level log-level)
(.timestamp (.getTime instant)))]
(cond-> msg-builder
?err (.fullMessage (timbre/stacktrace ?err {:stacktrace-fonts {}}))
context (.additionalField "context" context)
?ns-str (.additionalField "namespace" ?ns-str)
?file (.additionalField "file" ?file)
?line (.additionalField "line" ?line))
(.build msg-builder)))

(defn gelf-appender
"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
Expand All @@ -49,9 +74,5 @@
: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. (force msg_) (force hostname_))
(.level log-level) .build)]
(.send gelf-transport gelf-message)))})))
(.send (get-in data [:appender :gelf-transport])
(data->gelf-message data)))})))